replaceRange method
Replaces a range of elements with the elements of replacements
.
Removes the objects in the range from start
to end
, then inserts the elements of replacements
at start
.
This will change the size of this slice by replacements.length - (end - start)
.
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 replaceRange(int start, int end, Iterable<T> replacements) {
final (normalizedStart, normalizedEnd) =
_validateAndNormalizeRange(start, end);
final replacementsList = replacements.toList(growable: false);
_list.replaceRange(normalizedStart, normalizedEnd, replacementsList);
final replacementsLength = replacementsList.length;
final diff = replacementsLength - (normalizedEnd - normalizedStart);
_end += diff;
}