Behaviour of append (~=)

Lionello Lunesu lio at lunesu.remove.com
Tue May 30 04:37:02 PDT 2006


Why does the appending to a 'null' array cause the contents to be copied?

int[] ar1; // some array, not constant

int[] ar2 = null;
ar2 ~= ar1;
// ar2 !is ar1

But it could be like this:
if (ar2)
   ar2 ~= ar1;
else
   ar2 = ar1;

Wouldn't it be a good optimization for ~= to check for null first, to 
prevent the copy?

L.



More information about the Digitalmars-d-learn mailing list