authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2025-08-10 12:43:21-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-10 19:49:02-07:00
log3280fc98f3b0400c4ce0b8c54a157f1858490351
tree7eb0a734a889c103d3d140964ca8ff01e5844f78
parentb9a6dae2ae68d74d7f2fc2bfe394eb506fb7ca69

Writer: Delete writePreserve/writeAllPreserve

This is one way of partially addressing https://github.com/ziglang/zig/issues/24767 - These functions are unused - These functions are untested - These functions are broken + The same dangling pointer bug from 6219c015d8e8c958d96e5caa5ef0dbab9c414996 exists in `writePreserve` + The order of the bytes preserved in relation to the `bytes` being written can differ depending on unused buffer capacity at the time of the call and the drain implementation. If there ends up being a need for these functions, they can be fixed and added back.

1 files changed, 0 insertions(+), 31 deletions(-)

lib/std/Io/Writer.zig-31
...@@ -498,25 +498,6 @@ pub fn write(w: *Writer, bytes: []const u8) Error!usize {...@@ -498,25 +498,6 @@ pub fn write(w: *Writer, bytes: []const u8) Error!usize {
498 return w.vtable.drain(w, &.{bytes}, 1);498 return w.vtable.drain(w, &.{bytes}, 1);
499}499}
500500
501/// Asserts `buffer` capacity exceeds `preserve_len`.
502pub fn writePreserve(w: *Writer, preserve_len: usize, bytes: []const u8) Error!usize {
503 assert(preserve_len <= w.buffer.len);
504 if (w.end + bytes.len <= w.buffer.len) {
505 @branchHint(.likely);
506 @memcpy(w.buffer[w.end..][0..bytes.len], bytes);
507 w.end += bytes.len;
508 return bytes.len;
509 }
510 const temp_end = w.end -| preserve_len;
511 const preserved = w.buffer[temp_end..w.end];
512 w.end = temp_end;
513 defer w.end += preserved.len;
514 const n = try w.vtable.drain(w, &.{bytes}, 1);
515 assert(w.end <= temp_end + preserved.len);
516 @memmove(w.buffer[w.end..][0..preserved.len], preserved);
517 return n;
518}
519
520/// Calls `drain` as many times as necessary such that all of `bytes` are501/// Calls `drain` as many times as necessary such that all of `bytes` are
521/// transferred.502/// transferred.
522pub fn writeAll(w: *Writer, bytes: []const u8) Error!void {503pub fn writeAll(w: *Writer, bytes: []const u8) Error!void {
...@@ -524,18 +505,6 @@ pub fn writeAll(w: *Writer, bytes: []const u8) Error!void {...@@ -524,18 +505,6 @@ pub fn writeAll(w: *Writer, bytes: []const u8) Error!void {
524 while (index < bytes.len) index += try w.write(bytes[index..]);505 while (index < bytes.len) index += try w.write(bytes[index..]);
525}506}
526507
527/// Calls `drain` as many times as necessary such that all of `bytes` are
528/// transferred.
529///
530/// When draining the buffer, ensures that at least `preserve_len` bytes
531/// remain buffered.
532///
533/// Asserts `buffer` capacity exceeds `preserve_len`.
534pub fn writeAllPreserve(w: *Writer, preserve_len: usize, bytes: []const u8) Error!void {
535 var index: usize = 0;
536 while (index < bytes.len) index += try w.writePreserve(preserve_len, bytes[index..]);
537}
538
539/// Renders fmt string with args, calling `writer` with slices of bytes.508/// Renders fmt string with args, calling `writer` with slices of bytes.
540/// If `writer` returns an error, the error is returned from `format` and509/// If `writer` returns an error, the error is returned from `format` and
541/// `writer` is not called again.510/// `writer` is not called again.