resize method
Changes the buffer size and/or policy at runtime.
Shrinking the buffer drops the excess according to the current policy and counts the drops. A capacity of zero clears the buffer.
Implementation
void resize(int? capacity, {BufferOverflow? overflow}) {
if (capacity != null && capacity < 0) {
throw ArgumentError.value(capacity, 'capacity', 'must be null or >= 0');
}
_bufferCapacity = capacity;
if (overflow != null) _bufferOverflow = overflow;
final limit = _bufferCapacity;
if (limit == null) return;
final before = _dropped;
while (_buffer.length > limit) {
if (_bufferOverflow == BufferOverflow.dropNewest) {
_buffer.removeLast();
} else {
_buffer.removeFirst();
}
_dropped++;
}
if (_dropped > before) _reportOverflow(limit);
}