http://d.puremagic.com/issues/show_bug.cgi?id=2750





------- Comment #1 from snake.sc...@gmail.com  2009-03-19 15:40 -------
Sorry, bad example.  The patched compiler simply optimized the copy away, which
wasn't bad in itself, but neither was what I wanted to demonstrate.  Here's a
better example:

void main() {
    auto h = "hello\n";
    auto buf = new char[16];
    buf[0 .. h.length] = h;
}

Original 1.041:

__Dmain comdat
        assume  CS:__Dmain
L0:             sub     ESP,018h
                mov     EDX,FLAT:_DATA[0Ch]
                mov     EAX,FLAT:_DATA[08h]
                push    EBX
                push    ESI
                mov     ESI,EDX
                push    EDI
                lea     EDI,0Ch[ESP]
                movsd
                movsb
                movsb
                lea     ESI,0Ch[ESP]
                mov     ECX,offset FLAT:_D11TypeInfo_Aa6__initZ
                push    010h
                push    ECX
                call    near ptr __d_newarrayiT
                mov     EBX,6
                mov     ECX,EBX
                mov     EDI,EDX
                rep
                movsb
                add     ESP,8
                xor     EAX,EAX
                pop     EDI
                pop     ESI
                pop     EBX
                add     ESP,018h
                ret
__Dmain ends

Assembly produced by a patched compiler:

__Dmain comdat
        assume  CS:__Dmain
L0:             sub     ESP,01Ch
                mov     EDX,FLAT:_DATA[0Ch]
                mov     EAX,FLAT:_DATA[08h]
                push    ESI
                mov     ESI,EDX
                push    EDI
                lea     EDI,0Ch[ESP]
                movsd
                movsb
                movsb
                mov     ECX,offset FLAT:_D11TypeInfo_Aa6__initZ
                push    010h
                push    ECX
                call    near ptr __d_newarrayiT
                lea     ESI,014h[ESP]
                mov     EDI,EDX
                movsd
                movsb
                movsb
                add     ESP,8
                xor     EAX,EAX
                pop     EDI
                pop     ESI
                add     ESP,01Ch
                ret
__Dmain ends


-- 

Reply via email to