addAll method

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

Appends all objects of iterable to the end of this slice. Extends the length of the underlying list and this slice by the number of objects in iterable. The underlying list must be growable. Note, the ranges of other slices on the underlying list will not change, therefore use with care as this may shift the underlying data in other slices.

Implementation

@override
void addAll(Iterable<T> iterable) {
  final toAdd = iterable.toArr();
  final toAddLength = toAdd.length;
  if (toAddLength == 0) {
    return;
  }
  final listLength = _list.length;
  if (_end == listLength) {
    _list.addAll(toAdd);
  } else {
    final newList = List.generate(listLength + toAddLength, (i) {
      if (i < _end) {
        return _list[i];
      }
      if (i < _end + toAddLength) {
        return toAdd[i - _end];
      }
      return _list[i - toAddLength];
    });
    _list.clear();
    _list.addAll(newList);
  }
  _end += toAddLength;
}