diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-04-03 21:18:31 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-03 21:18:31 +0200 |
| commit | ff8f2eff3ab7fb412c5e2785ab90b29d02681fdb (patch) | |
| tree | ae0f3c3e436bc840e638bedf0e034824e987b780 /library/std/src | |
| parent | 9d733eca06f7ab138925e0db260955fd32135d87 (diff) | |
| parent | 878786848fdbe29325e9172d0ab86ed964eca7a6 (diff) | |
| download | rust-ff8f2eff3ab7fb412c5e2785ab90b29d02681fdb.tar.gz rust-ff8f2eff3ab7fb412c5e2785ab90b29d02681fdb.zip | |
Rollup merge of #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.
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/io/buffered/bufreader/buffer.rs | 1 | ||||
| -rw-r--r-- | library/std/src/io/copy.rs | 5 |
2 files changed, 4 insertions, 2 deletions
diff --git a/library/std/src/io/buffered/bufreader/buffer.rs b/library/std/src/io/buffered/bufreader/buffer.rs index 9fd2472ebdf..574288e579e 100644 --- a/library/std/src/io/buffered/bufreader/buffer.rs +++ b/library/std/src/io/buffered/bufreader/buffer.rs @@ -123,7 +123,6 @@ impl Buffer { /// Remove bytes that have already been read from the buffer. pub fn backshift(&mut self) { self.buf.copy_within(self.pos.., 0); - self.initialized -= self.pos; self.filled -= self.pos; self.pos = 0; } diff --git a/library/std/src/io/copy.rs b/library/std/src/io/copy.rs index 8d733325b3b..15e962924ac 100644 --- a/library/std/src/io/copy.rs +++ b/library/std/src/io/copy.rs @@ -248,8 +248,11 @@ impl<I: Write + ?Sized> BufferedWriterSpec for BufWriter<I> { Err(e) => return Err(e), } } else { + // All the bytes that were already in the buffer are initialized, + // treat them as such when the buffer is flushed. + init += buf.len(); + self.flush_buf()?; - init = 0; } } } |
