addAll method

void addAll (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

void addAll(Iterable<E> iterable) {
  if (iterable is List) {
    var list = iterable;
    int addCount = list.length;
    int 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.
      int endSpace = _table.length - _tail;
      if (addCount < endSpace) {
        _table.setRange(_tail, _tail + addCount, list, 0);
        _tail += addCount;
      } else {
        int preSpace = addCount - endSpace;
        _table.setRange(_tail, _tail + endSpace, list, 0);
        _table.setRange(0, preSpace, list, endSpace);
        _tail = preSpace;
      }
    }
  } else {
    for (E element in iterable) _add(element);
  }
}