Work around conservative optimization

Kagamin spam at here.lot
Mon Jun 4 08:44:48 UTC 2018


On Saturday, 2 June 2018 at 18:32:37 UTC, Johan Engelen wrote:
> ```
> void store32_le_optim(ref ubyte[4] dest, uint val)
> {
>     import core.stdc.string;
>     ubyte[4] temp;
>     temp[0]=cast(ubyte)val;
>     temp[1]=cast(ubyte)(val>>8);
>     temp[2]=cast(ubyte)(val>>16);
>     temp[3]=cast(ubyte)(val>>24);
>     memcpy(&dest, &temp, temp.sizeof);
> }
> ```

void store32_le_optim(ref ubyte[4] dest, uint val)
{
     import core.stdc.string;
     ubyte[4] temp;
     temp[0]=cast(ubyte)val;
     temp[1]=cast(ubyte)(val>>8);
     temp[2]=cast(ubyte)(val>>16);
     temp[3]=val>>24;
     dest=temp;
}

this works; CTFE doesn't support memcpy.


More information about the digitalmars-d-ldc mailing list