swapWithSlice method

void swapWithSlice(
  1. Slice<T> other
)

Swaps all elements in this with those in other. The length of other must be the same as this. Will panic if the length of other is not the same as this.

Implementation

void swapWithSlice(Slice<T> other) {
  final length = len();
  final otherLength = other.len();
  if (length != otherLength) {
    panic(
        "Slices must be the same length, this is `$length` and other is `$otherLength");
  }
  for (var i = 0; i < length; i++) {
    var temp = _list[i + _start];
    _list[i + _start] = other._list[i + other._start];
    other._list[i + other._start] = temp;
  }
}