addAll method

  1. @override
void addAll(
  1. Iterable<E> iterable
)
override

Adds all elements of iterable at the end of the queue. The length of the queue is extended by the length of iterable.

Implementation

@override
void addAll(Iterable<E> iterable) {
  if (iterable is List) {
    var list = iterable;
    var addCount = list.length;
    var length = this.length;
    if (length + addCount >= _table.length) {
      _preGrow(length + addCount);
      // After preGrow, all elements are at the start of the list.
      _table.setRange(length, length + addCount, list, 0);
      _tail += addCount;
    } else {
      // Adding addCount elements won't reach _head.
      var endSpace = _table.length - _tail;
      if (addCount < endSpace) {
        _table.setRange(_tail, _tail + addCount, list, 0);
        _tail += addCount;
      } else {
        var preSpace = addCount - endSpace;
        _table.setRange(_tail, _tail + endSpace, list, 0);
        _table.setRange(0, preSpace, list, endSpace);
        _tail = preSpace;
      }
    }
  } else {
    for (var element in iterable) {
      _add(element);
    }
  }
}