Skip to content

Commit 3280fc9

Browse files
squeek502andrewrk
authored andcommitted
Writer: Delete writePreserve/writeAllPreserve
This is one way of partially addressing #24767 - These functions are unused - These functions are untested - These functions are broken + The same dangling pointer bug from 6219c01 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 parent b9a6dae commit 3280fc9

File tree

1 file changed

+0
-31
lines changed

1 file changed

+0
-31
lines changed

lib/std/Io/Writer.zig

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -498,44 +498,13 @@ pub fn write(w: *Writer, bytes: []const u8) Error!usize {
498498
return w.vtable.drain(w, &.{bytes}, 1);
499499
}
500500

501-
/// Asserts `buffer` capacity exceeds `preserve_len`.
502-
pub 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-
520501
/// Calls `drain` as many times as necessary such that all of `bytes` are
521502
/// transferred.
522503
pub fn writeAll(w: *Writer, bytes: []const u8) Error!void {
523504
var index: usize = 0;
524505
while (index < bytes.len) index += try w.write(bytes[index..]);
525506
}
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`.
534-
pub 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-
539508
/// Renders fmt string with args, calling `writer` with slices of bytes.
540509
/// If `writer` returns an error, the error is returned from `format` and
541510
/// `writer` is not called again.

0 commit comments

Comments
 (0)