1
Fork 0

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.
This commit is contained in:
Florian Hartwig 2017-10-07 14:49:42 +02:00
parent b67f4283b3
commit d52acbe37f

View file

@ -206,6 +206,14 @@ impl<'a> Read for &'a [u8] {
*self = b;
Ok(())
}
#[inline]
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
buf.extend_from_slice(*self);
let len = self.len();
*self = &self[len..];
Ok(len)
}
}
#[stable(feature = "rust1", since = "1.0.0")]