std.uuid: Update 4

Dmitry Olshansky dmitry.olsh at gmail.com
Sun Jun 17 01:15:00 PDT 2012


On 17.06.2012 12:04, Johannes Pfau wrote:
> Am Sat, 16 Jun 2012 21:11:51 +0400
> schrieb Dmitry Olshansky<dmitry.olsh at gmail.com>:
>>
>> Ah and another way to go about it is:
>> union {
>> 	ubyte[16] uuid;
>> 	size_t[16/size_t.sizeof] by_word;
>> }
>>
>
> Isn't that an optimization which should really be done by the compiler?
> It already knows that it's supposed to compare two ubyte[16]...

It knows that you compare two ubyte[16] that it.
It easily might miss the fact that one of them is always 0 in all 16 cells.

>
> Also how could the union solution be used without having to copy the
> data?

There is no copy it union, aka overlapped storage. In other words as 
these 16 bytes represented as (on 32bit) 4 size_t. They share memory 
location. It doesn't play nice with CTFE though, as it thinks unions to 
be plain struct last time I checked.

-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list