On Monday, 17 August 2015 at 22:34:36 UTC, Andrei Alexandrescu wrote:
On 8/17/15 2:51 PM, deadalnix wrote:
From the compiler perspective, the tag is much nicer. Compiler can use
jump table for instance.

The pointer is a more direct conduit to a jump table.

Not really, because it most likely doesn't point to where you need it, but to a `TypeInfo` struct instead, which doesn't help you in a `switch` statement. Besides, you probably shouldn't compare pointers vs integers, but pointers vs enums.


It is not a good solution for Variant (which needs to be able to represent arbitrary types) but if the amount of types is finite, tag is
almost always a win.
In the case of JSON, using a tag and packing trick, it is possible to pack everything in a 2 pointers sized struct without much trouble.

Point taken. Question is if this is worth it.

Anything that makes it fit in two registers instead of three (= 2 regs + memory, in practice) is most likely worth it.

Reply via email to