digitalmars.D.bugs - [Issue 12751] New: Avoid heap allocations in some cases of array
- via Digitalmars-d-bugs (65/65) May 16 2014 https://issues.dlang.org/show_bug.cgi?id=12751
https://issues.dlang.org/show_bug.cgi?id=12751 Issue ID: 12751 Summary: Avoid heap allocations in some cases of array concatenation Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: enhancement Priority: P1 Component: DMD Assignee: nobody puremagic.com Reporter: bearophile_hugs eml.cc void main() { int[10] a; int[20] b; int[30] c = a ~ b; } Compiled with -O -release -inline -noboundscheck (dmd 2.066alpha) gives: __Dmain comdat L0: sub ESP,0F8h mov ECX,0Ah xor EAX,EAX push EBX push ESI push EDI lea EDI,0Ch[ESP] rep stosd mov ECX,014h lea EDI,03Ch[ESP] rep stosd mov EAX,0Ah mov EBX,offset FLAT:_D11TypeInfo_Ai6__initZ push 078h lea ECX,040h[ESP] push ECX push 014h lea EDX,018h[ESP] push EDX push EAX push EBX call near ptr __d_arraycatT add ESP,014h push EDX lea ESI,094h[ESP] push ESI call near ptr _memcpy add ESP,0Ch xor EAX,EAX pop EDI pop ESI pop EBX add ESP,0F8h ret But the compiler should perform that operation without heap allocations. So that should also be writeable: void main() nogc { int[10] a; int[20] b; int[30] c = a ~ b; } --
May 16 2014