Possible change to array runtime?

Don x at nospam.com
Fri Mar 14 08:58:06 PDT 2014


On Friday, 14 March 2014 at 14:48:13 UTC, Steven Schveighoffer 
wrote:
> On Thu, 13 Mar 2014 11:24:01 -0400, Steven Schveighoffer 
> <schveiguy at yahoo.com> wrote:
>
>
>> arr.length = 0;
>>
> ...
>> 3. Don's company uses D1 as its language, I highly recommend 
>> watching Don's Dconf13 presentation (and look forward to his 
>> Dconf14 one!) to see how effective D code can create 
>> unbelievable speed, especially where array slices are 
>> concerned. But to the above line, in D2, they must add the 
>> following code to get the same behavior:
>>
>> arr.assumeSafeAppend();
>
> Just a quick note, buried in same thread that Don mentioned, he 
> outlined a more specific case, and this does not involve 
> setting length to 0, but to any arbitrary value.
>
> This means my approach does not help them, and although it 
> makes sense, the idea that it would help Sociomantic move to D2 
> is not correct.
>
> -Steve

Actually it would help a great deal. In most cases, we do set the 
length to 0. That example code is unusual.

FYI: In D1, this was the most important idiom in the language.
In the first D conference in 2007, a feature T[new] was 
described, specifically to support this idiom in a safe manner. 
Implementation was begun in the compiler. Unfortunately, it 
didn't happen in the end. I'm not sure if it would actually have 
worked or not.


BTW you said somewhere that concatenation always allocates. What 
I actually meant was ~=, not ~. In our code it is always preceded 
by .length = 0 though.
It's important that ~= should not allocate, when the existing 
capacity is large enough.




More information about the Digitalmars-d mailing list