On 04/12/2013 10:14 AM, Manu wrote:
String concatenation is rampant! Look at this code to parse the env
variables (which are already an AA):
foreach (var, val; childEnv)
envz[pos++] = (var~'='~val~'\0').ptr;
This could be improved. It could also be optimized into a single
allocation automatically by the compiler (it might already be). The
API would not be affected by this improvement, though.
I've never seem the compiler apply that optimisation, although I often
wish it would.
I saw an appender appear a few pages below, that would be an improvement
here too I guess.
It is only a single runtime call to _d_arraycatnT which precomputes the
resulting length.
https://github.com/D-Programming-Language/druntime/blob/e5415ed4f0638fcd1d0f8e06aec4197ad108449f/src/rt/lifetime.d#L2031