diff options
| author | Pietro Albini <pietro@pietroalbini.org> | 2018-12-19 11:47:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-19 11:47:04 +0100 |
| commit | cf9fd6074da321b353a755359fac10cd28ed251d (patch) | |
| tree | 3d91966504b019e969eff6562c053a904629114b /src | |
| parent | e7b4bc35e99ee3c5b2b42a1b8b3f9cd6eca1f0b2 (diff) | |
| parent | a1790e8c200335b6f41f09bb7c7d17bd65b43f8a (diff) | |
| download | rust-cf9fd6074da321b353a755359fac10cd28ed251d.tar.gz rust-cf9fd6074da321b353a755359fac10cd28ed251d.zip | |
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)
Diffstat (limited to 'src')
| -rw-r--r-- | src/libstd/io/mod.rs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index dc97701d889..5137a9432ae 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -271,6 +271,7 @@ use cmp; use fmt; +use slice; use str; use memchr; 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. /// /// 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>; 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)), + }; + } } } |
