copyWithin method

void copyWithin(
  1. int start,
  2. int end,
  3. int dst, {
  4. bool sInc = true,
  5. bool enInc = false,
})

Copies elements from one part of the slice to another part of itself The edge conditions can be changes with sInc and eInc. sInc is whether the start is inclusive and eInc is whether the end is inclusive.

Implementation

void copyWithin(int start, int end, int dst,
    {bool sInc = true, bool enInc = false}) {
  if (!sInc) start += 1;
  if (enInc) end += 1;
  final length = len();
  if (start < 0 ||
      start >= length ||
      end < 0 ||
      end > length ||
      dst < 0 ||
      dst >= length) {
    panic("Index out of bounds");
  }
  if (dst < start) {
    for (var i = start, j = dst; i < end; i++, j++) {
      _list[j + _start] = _list[i + _start];
    }
  } else {
    for (var i = end - 1, j = dst + end - start - 1; i >= start; i--, j--) {
      _list[j + _start] = _list[i + _start];
    }
  }
}