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.
This commit is contained in:
Matthias Krüger 2025-04-03 21:18:31 +02:00 committed by GitHub
commit ff8f2eff3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View file

@ -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;
}

View file

@ -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;
}
}
}