length property

int length

Returns the number of elements in the iterable.

This is an efficient operation that doesn't require iterating through the elements.

Implementation

int get length => (_tail - _head) & (_table.length - 1);
void length= (int value)
override

Changes the length of this list.

If newLength is greater than the current length, entries are initialized to null.

Throws an UnsupportedError if the list is fixed-length.

Implementation

set length(int value) {
  if (value < 0) throw new RangeError("Length $value may not be negative.");

  int delta = value - length;
  if (delta >= 0) {
    if (_table.length <= value) {
      _preGrow(value);
    }
    _tail = (_tail + delta) & (_table.length - 1);
    return;
  }

  int newTail = _tail + delta; // [delta] is negative.
  if (newTail >= 0) {
    _table.fillRange(newTail, _tail, null);
  } else {
    newTail += _table.length;
    _table.fillRange(0, _tail, null);
    _table.fillRange(newTail, _table.length, null);
  }
  _tail = newTail;
}