On 3/14/2014 3:06 AM, Don wrote:
Our entire codebase assumes that stomping will happen. Simplest example:

T[] dupArray(T)(ref T[] dest, T[] src)
{
     dest.length = src.length;
     if (src.length) {
         dest[] = src[];
     }
     return dest;
}

This is equivalent to dest = src.dup, but if dest was already long enough to
contain src, no allocation occurs.

Sure, we can add a call to "assumeSafeAppend()" everywhere. And I mean
*everywhere*. Every single instance of array creation or concatentation, without
exception. Almost every array in our codebase is affected by this.

I see. I'd start by replacing T[] with:

   alias T[] Q;

and then using Q instead of T[]. Once that is done, you can experiment with different implementations of Q. In my own D code, I've found this to be very effective. It's great to be able to swap in/out utterly different implementations of Q and measure performance.

Reply via email to