Writes the same byte many times, performing the underlying write call as many times as necessary.
On success, at least preserve bytes will remain buffered if there are
enough buffered bytes to do so.
The amount buffered by the writer after the call will only be less than
preserve if w.end + n is less than preserve before the call.
The intentionally preserved bytes will include up to preserve -| n bytes from
the previously buffered bytes, plus @min(n, preserve_len) of the newly
written bytes.
Asserts buffer capacity is at least preserve.
n can be greater than the buffer capacity.
pub fn splatBytePreserve(w: *Writer, preserve: usize, byte: u8, n: usize) Error!void
pub fn splatBytePreserve(w: *Writer, preserve: usize, byte: u8, n: usize) Error!void {
const new_end = w.end + n;
if (new_end <= w.buffer.len) {
@memset(w.buffer[w.end..][0..n], byte);
w.end = new_end;
return;
}
// If `n` is large, we can ignore `preserve` up to a point.
var remaining = n;
while (remaining > preserve) {
assert(remaining != 0);
remaining -= try splatByte(w, byte, remaining - preserve);
if (w.end + remaining <= w.buffer.len) {
@memset(w.buffer[w.end..][0..remaining], byte);
w.end += remaining;
return;
}
}
// Ensure the contract of `rebase` is upheld.
assert(w.end + remaining > w.buffer.len);
// Offset the amount preserved by the amount we have left to splat
// since the remaining splat is always going to be part of that
// preservation.
try w.vtable.rebase(w, preserve -| remaining, remaining);
@memset(w.buffer[w.end..][0..remaining], byte);
w.end += remaining;
}