Inline Bytes::next and Bytes::size_hint.

This greatly increases its speed.
This commit is contained in:
Nicholas Nethercote 2023-10-12 10:49:32 +11:00
parent 64368d0279
commit 4d6810844e

View File

@ -2777,6 +2777,7 @@ pub struct Bytes<R> {
impl<R: Read> Iterator for Bytes<R> { impl<R: Read> Iterator for Bytes<R> {
type Item = Result<u8>; type Item = Result<u8>;
#[inline]
fn next(&mut self) -> Option<Result<u8>> { fn next(&mut self) -> Option<Result<u8>> {
let mut byte = 0; let mut byte = 0;
loop { loop {
@ -2789,6 +2790,7 @@ fn next(&mut self) -> Option<Result<u8>> {
} }
} }
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) { fn size_hint(&self) -> (usize, Option<usize>) {
SizeHint::size_hint(&self.inner) SizeHint::size_hint(&self.inner)
} }