Faster way to .dup an AA?

Chris Nicholson-Sauls ibisbasenji at gmail.com
Tue May 1 22:53:56 PDT 2007


Jarrett Billingsley wrote:
> I'm currently doing something like this:
> 
> int[char[]] source;
> 
> ...
> 
> int[char[]] dest;
> 
> foreach(k, v; source)
>     dest[k] = v;
> 
> But that loop is not very high-performance.
> 
> Is there any other way to dup an AA that's better performance?  Something is 
> telling me "no."  It would be so nice if this were a supported property for 
> AAs, so the implementation could come up with a faster way to .dup it.. 
> 
> 

Sadly I haven't found anything either.  It seems they ought to have a direct .dup property 
just like fixed/variable arrays.  You can do (aa1 = aa2) but this turns out to be 
analogous to slicing; any later changes to aa1 also appear in aa2.

Which infers to me that AA's are referance types perchance??  At least insofar as arrays 
are, as a struct with a pointer?  This means there may be a "hack" to get a direct dup 
using memcpy, but I'm not sure how to get at that pointer safely.  Bah.

-- Chris Nicholson-Sauls


More information about the Digitalmars-d-learn mailing list