On 2010-02-17 18:38:55 -0500, Steven Schveighoffer <[email protected]> said:

One thing I like to do with array literals is use them for appending
several elements at once:

        array ~= [1, a+1, b+1];

This way I avoid multiple array appends so it should be faster, but if
that temporary array literal gets allocated on the heap then it's
rather counterproductive for me to use array literals for this.

Could cases like this, where the array never escape, be allocated on the stack?

Doesn't this do exactly that now?

array ~= 1 ~ (a+1) ~ (b+1);

It doesn't compile: Error: Can only concatenate arrays, not (int ~ int).

This works fine:

        array ~= [1] ~ (a+1) ~ (b+1);

but now we have added back an array literal. :-)

--
Michel Fortin
[email protected]
http://michelf.com/

Reply via email to