On 12/07/2017 03:07 PM, Iain Buclaw wrote:
On 7 December 2017 at 23:39, Daniel Kozak <[email protected]> wrote:
The other slowdown is caused by concatenation. Because std::string += is
more simillar to std.array.(Ref)Appender


Correct.  The semantics of ~= mean that the memory is copied around to
a new allocation every time (unless the array is marked
assumeSafeAppend).


You must have meant ~, not ~= because luckily, it is assumeSafeAppend when there is just one slice. ~= is not that bad in that case:

import std.stdio;

void main() {
    int[] a;
    foreach (i; 0 .. 10) {
        a ~= i;
        writeln(a.ptr);
    }
}

7F621818D020
7F621818D020
7F621818D020
7F621818C100
7F621818C100
7F621818C100
7F621818C100
7F621818B040
7F621818B040
7F621818B040

Ali

Reply via email to