Skip to content

Commit

Permalink
Use read_exact in Bytes::next.
Browse files Browse the repository at this point in the history
This is much faster.
  • Loading branch information
nnethercote committed Oct 12, 2023
1 parent 69ad06f commit ed2a587
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2781,13 +2781,10 @@ impl<R: Read> Iterator for Bytes<R> {

#[inline]
fn next(&mut self) -> Option<Result<u8>> {
loop {
return match self.inner.read(slice::from_mut(&mut self.byte)) {
Ok(0) => None,
Ok(..) => Some(Ok(self.byte)),
Err(ref e) if e.is_interrupted() => continue,
Err(e) => Some(Err(e)),
};
match self.inner.read_exact(slice::from_mut(&mut self.byte)) {
Ok(()) => Some(Ok(self.byte)),
Err(e) if e.kind() == ErrorKind::UnexpectedEof => None,
Err(e) => Some(Err(e)),
}
}

Expand Down

0 comments on commit ed2a587

Please sign in to comment.