Rollup merge of #56363 - Lucretiel:patch-3, r=shepmaster
Defactored Bytes::read Removed unneeded refactoring of read_one_byte, which removed the unneeded dynamic dispatch (`dyn Read`) used by that function. This function is only used in one place in the entire Rust codebase; there doesn't seem to be a reason for it to exist (and there especially doesn't seem to be a reason for it to use dynamic dispatch)
This commit is contained in:
commit
cf9fd6074d
1 changed files with 10 additions and 13 deletions
|
@ -271,6 +271,7 @@
|
||||||
|
|
||||||
use cmp;
|
use cmp;
|
||||||
use fmt;
|
use fmt;
|
||||||
|
use slice;
|
||||||
use str;
|
use str;
|
||||||
use memchr;
|
use memchr;
|
||||||
use ptr;
|
use ptr;
|
||||||
|
@ -1936,18 +1937,6 @@ impl<T: BufRead> BufRead for Take<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_one_byte(reader: &mut dyn Read) -> Option<Result<u8>> {
|
|
||||||
let mut buf = [0];
|
|
||||||
loop {
|
|
||||||
return match reader.read(&mut buf) {
|
|
||||||
Ok(0) => None,
|
|
||||||
Ok(..) => Some(Ok(buf[0])),
|
|
||||||
Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
|
|
||||||
Err(e) => Some(Err(e)),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An iterator over `u8` values of a reader.
|
/// An iterator over `u8` values of a reader.
|
||||||
///
|
///
|
||||||
/// This struct is generally created by calling [`bytes`] on a reader.
|
/// This struct is generally created by calling [`bytes`] on a reader.
|
||||||
|
@ -1965,7 +1954,15 @@ impl<R: Read> Iterator for Bytes<R> {
|
||||||
type Item = Result<u8>;
|
type Item = Result<u8>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Result<u8>> {
|
fn next(&mut self) -> Option<Result<u8>> {
|
||||||
read_one_byte(&mut self.inner)
|
let mut byte = 0;
|
||||||
|
loop {
|
||||||
|
return match self.inner.read(slice::from_mut(&mut byte)) {
|
||||||
|
Ok(0) => None,
|
||||||
|
Ok(..) => Some(Ok(byte)),
|
||||||
|
Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
|
||||||
|
Err(e) => Some(Err(e)),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue