patchInPlace method
Replaces replaced elements starting at from with patch in place.
Implementation
@override
ListBuffer<A> patchInPlace(int from, RIterableOnce<A> patch, int replaced) {
final len_ = _len;
final from_ = max(from, 0); // normalized
final replaced_ = max(replaced, 0); // normalized
final it = patch.iterator;
final nonEmptyPatch = it.hasNext;
final nonEmptyReplace = (from_ < len_) && (replaced_ > 0);
// don't want to add a mutation or check aliasing (potentially expensive)
// if there's no patching to do
if (nonEmptyPatch || nonEmptyReplace) {
final fresh = ListBuffer<A>()._freshFrom(it);
_ensureUnaliased();
final i = min(from_, len_);
final n = min(replaced_, len_);
final p = _locate(i);
_removeAfter(p, min(n, len_ - i));
_insertAfter(p, fresh);
}
return this;
}