Skip to content

Commit a7ffaca

Browse files
authored
Rollup merge of rust-lang#139068 - a1phyr:less_uninit, r=joboet
io: Avoid marking some bytes as uninit These bytes were marked as uninit, which would cause them to be initialized multiple times even though it was not necessary.
2 parents 0cce469 + 5509c52 commit a7ffaca

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Diff for: std/src/io/buffered/bufreader/buffer.rs

-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ impl Buffer {
123123
/// Remove bytes that have already been read from the buffer.
124124
pub fn backshift(&mut self) {
125125
self.buf.copy_within(self.pos.., 0);
126-
self.initialized -= self.pos;
127126
self.filled -= self.pos;
128127
self.pos = 0;
129128
}

Diff for: std/src/io/copy.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,11 @@ impl<I: Write + ?Sized> BufferedWriterSpec for BufWriter<I> {
248248
Err(e) => return Err(e),
249249
}
250250
} else {
251+
// All the bytes that were already in the buffer are initialized,
252+
// treat them as such when the buffer is flushed.
253+
init += buf.len();
254+
251255
self.flush_buf()?;
252-
init = 0;
253256
}
254257
}
255258
}

0 commit comments

Comments
 (0)