Skip to content

Commit d52acbe

Browse files
committed
Add read_to_end implementation to &[u8]'s Read impl
The default impl for read_to_end does a bunch of bookkeeping that isn't necessary for slices and is about 4 times slower on my machine.
1 parent b67f428 commit d52acbe

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/libstd/io/impls.rs

+8
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ impl<'a> Read for &'a [u8] {
206206
*self = b;
207207
Ok(())
208208
}
209+
210+
#[inline]
211+
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
212+
buf.extend_from_slice(*self);
213+
let len = self.len();
214+
*self = &self[len..];
215+
Ok(len)
216+
}
209217
}
210218

211219
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)