Do equality checks for dynamic arrays attempt to shortcut with pointer comparison

monarch_dodra monarchdodra at gmail.com
Thu Apr 3 00:54:07 PDT 2014


On Thursday, 3 April 2014 at 07:03:26 UTC, dnspies wrote:
> If two dynamic arrays point to the same place in memory, is it 
> fast to compare them for equality? or does every element still 
> have to be compared?

Depends how you test for equality.

If you use "is", the "opEquals" will straight up check that the 
slices are the actual same slice (point to same memory, same 
length).

If you use "==" or "[] == []" (which is equivalent), then it will 
check the lengths, then the pointers, and finally, the elements.


More information about the Digitalmars-d-learn mailing list