On Saturday, 23 April 2016 at 14:10:06 UTC, Basile B wrote:
On Saturday, 23 April 2016 at 13:37:31 UTC, Andrei Alexandrescu wrote:
https://issues.dlang.org/show_bug.cgi?id=15951. I showed a few obvious cases, but finding the best code in general is tricky. Ideas? -- Andrei

In the first example you've forget to assign void:

http://d.godbolt.org/#compilers:!((compiler:gdc46,options:'-O3',source:'struct+RCStr(C)%0A%7B%0A++++enum+uint+maxSmall+%3D+64+/+C.sizeof+-+1%3B%0A++++C%5BmaxSmall%5D+small+%3D+void%3B%0A++++ubyte+smallLen+%3D+void%3B%0A%7D%0A%0Aauto+fun()+%7B%0A++RCStr!!char+result+%3D+void%3B%0A++return+result%3B%0A%7D%0A')),filterAsm:(commentOnly:!t,directives:!t,labels:!t),version:3

to get the real equivalent to the C++ version.

The problem in the second example is that the full initializer is always copied from the static layout typeid(Stuff).initializer[0..$], despite of the fact that some of the members are not iitialized, while in C++ only members that are init are copied.

The DMD code is shorter than the GDC one because it copies the initializer with `rep movsq` while GDC unrolls the `rep` with a bunch of `movq`, but in both cases the init is always fully copied.

So the problem is the suboptimal copy of the initializer.

I haven't seen but this problem is actually well known:

https://issues.dlang.org/show_bug.cgi?id=11817
https://issues.dlang.org/show_bug.cgi?id=11331

It really looks that this can only be solved by a compiler update. Even with a custom this() with params and a the default this() disabled the initializer is **always** copied.

Reply via email to