Skip to content

Commit cf9fd60

Browse files
authored
Rollup merge of rust-lang#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)
2 parents e7b4bc3 + a1790e8 commit cf9fd60

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/libstd/io/mod.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@
271271

272272
use cmp;
273273
use fmt;
274+
use slice;
274275
use str;
275276
use memchr;
276277
use ptr;
@@ -1936,18 +1937,6 @@ impl<T: BufRead> BufRead for Take<T> {
19361937
}
19371938
}
19381939

1939-
fn read_one_byte(reader: &mut dyn Read) -> Option<Result<u8>> {
1940-
let mut buf = [0];
1941-
loop {
1942-
return match reader.read(&mut buf) {
1943-
Ok(0) => None,
1944-
Ok(..) => Some(Ok(buf[0])),
1945-
Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
1946-
Err(e) => Some(Err(e)),
1947-
};
1948-
}
1949-
}
1950-
19511940
/// An iterator over `u8` values of a reader.
19521941
///
19531942
/// This struct is generally created by calling [`bytes`] on a reader.
@@ -1965,7 +1954,15 @@ impl<R: Read> Iterator for Bytes<R> {
19651954
type Item = Result<u8>;
19661955

19671956
fn next(&mut self) -> Option<Result<u8>> {
1968-
read_one_byte(&mut self.inner)
1957+
let mut byte = 0;
1958+
loop {
1959+
return match self.inner.read(slice::from_mut(&mut byte)) {
1960+
Ok(0) => None,
1961+
Ok(..) => Some(Ok(byte)),
1962+
Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
1963+
Err(e) => Some(Err(e)),
1964+
};
1965+
}
19691966
}
19701967
}
19711968

0 commit comments

Comments
 (0)