Skip to content

Commit ab19755

Browse files
committed
bufreader::Buffer::backshift: don't move the uninit bytes
previous code was perfectly sound because of MaybeUninit, but it did waste cycles on copying memory that is known to be uninitialized.
1 parent 425a9c0 commit ab19755

File tree

1 file changed

+1
-1
lines changed
  • library/std/src/io/buffered/bufreader

1 file changed

+1
-1
lines changed

library/std/src/io/buffered/bufreader/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl Buffer {
122122

123123
/// Remove bytes that have already been read from the buffer.
124124
pub fn backshift(&mut self) {
125-
self.buf.copy_within(self.pos.., 0);
125+
self.buf.copy_within(self.pos..self.filled, 0);
126126
self.filled -= self.pos;
127127
self.pos = 0;
128128
}

0 commit comments

Comments
 (0)