Faster way to .dup an AA?

Bill Baxter dnewsgroup at billbaxter.com
Wed May 2 01:32:20 PDT 2007


Chris Nicholson-Sauls wrote:
> 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.


I think that's pretty hopeless.  AA's should have a dup property, plain 
and simple.  The implementation of AA's isn't specified by the spec (I 
don't think the performance characteristics even are), so anything you 
manage to get working in terms of a "raw dup" is going to be 
implementation-dependent.

--bb


More information about the Digitalmars-d-learn mailing list