Skip to content

Commit f802233

Browse files
authored
Rollup merge of rust-lang#145538 - lolbinarycat:std-bufreader-buffer-backshift-less, r=tgross35
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.
2 parents 870e8a0 + 7941af7 commit f802233

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

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)