Change representation of dynamic arrays?

Derek Parnell derek at psych.ward
Sun Oct 21 02:55:41 PDT 2007


On Fri, 19 Oct 2007 20:03:02 -0700, Walter Bright wrote:
> So, what do you think?

My first concern was for the speed of accessing the length, either through
.length property or the $ concept.

I've examined my usage of .length and about 80% of the time I'm comparing
it to zero ...

   if (X.length == 0)
   if (X.length > 0) 

About another 10% is comparing the length of one array to another array ...

   if (X.length == Y.length)

Most of the rest is extracting right hand slices (substrings typically) ...

    result = X[$ - a .. $ - b]

Only occasionally do I set the .length

Most of my array iterations use the foreach() construct.

So it seems that it would be beneficial change for me. It certainly won't
break any of my code because I don't try to access the ABI directly, only
through .ptr and .length.

My test for an empty array is to compare the length. My test for an
unassigned array is to test the .ptr value to null. So I think that a good
built-in property would be an .isEmpty concept. 

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell



More information about the Digitalmars-d mailing list