| ... | ... | @@ -417,7 +417,8 @@ pub fn writableSliceGreedyPreserve(w: *Writer, preserve: usize, minimum_len: usi |
| 417 | 417 | return w.buffer[w.end..]; |
| 418 | 418 | } |
| 419 | 419 | |
| 420 | | /// Asserts the provided buffer has total capacity enough for `len`. |
| 420 | /// Asserts the provided buffer has total capacity enough for `len` |
| 421 | /// and `preserve` combined. |
| 421 | 422 | /// |
| 422 | 423 | /// Advances the buffer end position by `len`. |
| 423 | 424 | /// |
| ... | ... | @@ -755,8 +756,14 @@ pub fn writeByte(w: *Writer, byte: u8) Error!void { |
| 755 | 756 | } |
| 756 | 757 | } |
| 757 | 758 | |
| 758 | | /// When draining the buffer, ensures that at least `preserve` bytes |
| 759 | | /// remain buffered. |
| 759 | /// On success, at least `preserve` bytes will remain buffered if there are |
| 760 | /// enough buffered bytes to do so. |
| 761 | /// The amount buffered by the writer after the call will only be less than |
| 762 | /// `preserve` if `w.end + 1` is less than `preserve` before the call. |
| 763 | /// The intentionally preserved bytes will include up to `preserve -| 1` bytes from |
| 764 | /// the previously buffered bytes, plus the newly written byte. |
| 765 | /// |
| 766 | /// Asserts buffer capacity is at least `preserve`. |
| 760 | 767 | pub fn writeBytePreserve(w: *Writer, preserve: usize, byte: u8) Error!void { |
| 761 | 768 | if (w.buffer.len - w.end != 0) { |
| 762 | 769 | @branchHint(.likely); |
| ... | ... | @@ -784,6 +791,19 @@ test splatByteAll { |
| 784 | 791 | try testing.expectEqualStrings(&@as([45]u8, @splat('7')), aw.writer.buffered()); |
| 785 | 792 | } |
| 786 | 793 | |
| 794 | /// Writes the same byte many times, performing the underlying write call as |
| 795 | /// many times as necessary. |
| 796 | /// |
| 797 | /// On success, at least `preserve` bytes will remain buffered if there are |
| 798 | /// enough buffered bytes to do so. |
| 799 | /// The amount buffered by the writer after the call will only be less than |
| 800 | /// `preserve` if `w.end + n` is less than `preserve` before the call. |
| 801 | /// The intentionally preserved bytes will include up to `preserve -| n` bytes from |
| 802 | /// the previously buffered bytes, plus `@min(n, preserve_len)` of the newly |
| 803 | /// written bytes. |
| 804 | /// |
| 805 | /// Asserts buffer capacity is at least `preserve`. |
| 806 | /// `n` can be greater than the buffer capacity. |
| 787 | 807 | pub fn splatBytePreserve(w: *Writer, preserve: usize, byte: u8, n: usize) Error!void { |
| 788 | 808 | const new_end = w.end + n; |
| 789 | 809 | if (new_end <= w.buffer.len) { |