Skip to content

Commit

Permalink
Add read_to_end implementation to &[u8]'s Read impl
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fhartwig committed Oct 7, 2017
1 parent b67f428 commit d52acbe
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/libstd/io/impls.rs
Expand Up @@ -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")]
Expand Down

0 comments on commit d52acbe

Please sign in to comment.