| ... | @@ -85,6 +85,16 @@ pub const AllocatingWriter = struct { | ... | @@ -85,6 +85,16 @@ pub const AllocatingWriter = struct { |
| 85 | self.capacity = 0; | 85 | self.capacity = 0; |
| 86 | } | 86 | } |
| 87 | | 87 | |
| | 88 | pub fn replaceRangeAssumeCapacity(self: *AllocatingWriter, start: usize, len: usize, new_items: []const u8) void { |
| | 89 | std.debug.assert(self.capacity - self.items.len >= new_items.len -| len); |
| | 90 | const tail = self.items[start + len ..]; |
| | 91 | const vacated = self.items[self.items.len - (len -| new_items.len) ..]; |
| | 92 | self.items.len = self.items.len - len + new_items.len; |
| | 93 | @memmove(self.items[start + new_items.len ..], tail); |
| | 94 | @memcpy(self.items[start..][0..new_items.len], new_items); |
| | 95 | @memset(vacated, undefined); |
| | 96 | } |
| | 97 | |
| 88 | const W = nio.Writable(@This(), ._var); | 98 | const W = nio.Writable(@This(), ._var); |
| 89 | pub const writeAll = W.writeAll; | 99 | pub const writeAll = W.writeAll; |
| 90 | pub const writevAll = W.writevAll; | 100 | pub const writevAll = W.writevAll; |