fillRange method Null safety

void fillRange(
  1. int start,
  2. int end,
  3. [int? value]
)
inherited

Overwrites a range of elements with fillValue.

Sets the positions greater than or equal to start and less than end, to fillValue.

The provided range, given by start and end, must be valid. A range from start to end is valid if 0 ≤ startendlength. An empty range (with end == start) is valid.

Example:

var list = List.filled(5, -1);
print(list); //  [-1, -1, -1, -1, -1]
list.fillRange(1, 3, 4);
print(list); //  [-1, 4, 4, -1, -1]

If the element type is not nullable, the fillValue must be provided and must be non-null.

Implementation

void fillRange(int start, int end, [E? value]) {
  var startInTable = (_head + start) & (_table.length - 1);
  var endInTable = (_head + end) & (_table.length - 1);
  if (startInTable <= endInTable) {
    _table.fillRange(startInTable, endInTable, value);
  } else {
    _table.fillRange(startInTable, _table.length, value);
    _table.fillRange(0, endInTable, value);
  }
}