Change representation of dynamic arrays?

Janice Caron caron800 at googlemail.com
Sat Oct 20 08:44:06 PDT 2007


Walter, I think we might want a new property, isEmpty, for arrays (and
collections in general).

See, we can't test for (array == null), because as you know, a
non-null array can still be empty.

The test (array.length == 0) will still work, but since calculating
.length might involve a divide, it's no longer guaranteed to be
optimal. (Also, I can imagine collection in which .length might be
O(N)).

We could test for (array.start == array.end). In fact, that's probably
the best approach, given what you've told us so far. But is there a
guarantee that that would necessarily be the most efficient test for
collections in general? I can imagine collections in which .end might
involve a non-trivial calculation.

.isEmpty would be clean, simple, and obvious.



More information about the Digitalmars-d mailing list