Skip to content

Commit

Permalink
Auto merge of rust-lang#116775 - nnethercote:inline-Bytes-next, r=the…
Browse files Browse the repository at this point in the history
…8472

Inline `Bytes::next` and `Bytes::size_hint`.

This greatly increases its speed. On one small test program using `Bytes::next` to iterate over a large file, execution time dropped from ~330ms to ~220ms.

r? `@the8472`
  • Loading branch information
bors committed Oct 16, 2023
2 parents 58352c0 + 4d68108 commit 99592fd
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2777,6 +2777,7 @@ pub struct Bytes<R> {
impl<R: Read> Iterator for Bytes<R> {
type Item = Result<u8>;

#[inline]
fn next(&mut self) -> Option<Result<u8>> {
let mut byte = 0;
loop {
Expand All @@ -2789,6 +2790,7 @@ impl<R: Read> Iterator for Bytes<R> {
}
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
SizeHint::size_hint(&self.inner)
}
Expand Down

0 comments on commit 99592fd

Please sign in to comment.