Fastest Way to Append Multiple Elements to an Array

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Dec 19 08:13:20 PST 2014


On 12/19/14 10:42 AM, zeljkog wrote:
> On 19.12.14 16:25, Steven Schveighoffer wrote:
>> This is surprising to me. I would expect especially ints to be faster.
>> In reality, there is no difference between arr ~= args and arr.length +=
>> args.length, and then copying, it's just how you do the copying. Perhaps
>> it's the call to memcpy in the runtime that is slower than looping.
>>
>
> I think it's compile time looping, it's unrolled.

Ah, good point. Your solution is definitely preferable then, and I hope 
at some point the compiler can make that the result of appending an 
array literal.

-Steve


More information about the Digitalmars-d-learn mailing list