pub fn splatBytePreserve(w: *Writer, preserve: usize, byte: u8, n: usize) Error!void w: *Writerpreserve: usizebyte: u8n: usizeWriteFailedSee the Writer implementation for detailed diagnostics.
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910pub 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;
}
Writes the same byte many times, performing the underlying write call as many times as necessary.
On success, at least
preservebytes 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 thanpreserveifw.end + nis less thanpreservebefore the call. The intentionally preserved bytes will include up topreserve -| nbytes from the previously buffered bytes, plus@min(n, preserve_len)of the newly written bytes.Asserts buffer capacity is at least
preserve.ncan be greater than the buffer capacity.