On 12/14/14 6:16 PM, "Nordlöw" wrote:
What's the fastest way to append multiple elements to an array?:
Before appending, call reserve to avoid the possibility of reallocating multiple times:
arr.reserve(arr.length + n); // about to append n elements.
Either arr ~= e1; arr ~= e2; arr ~= e3; or arr ~= [e1,e2,e3];
I wish this would be fastest, but it's not, because this allocates an array on the heap with elements e1, e2, e3 before appending. It would be a superb addition to D if this would simply allocate a stack array (if the array never escapes the expression).
-Steve