diff options
| author | Nathan West <Lucretiel@users.noreply.github.com> | 2018-11-29 20:36:32 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-29 20:36:32 -0500 |
| commit | f59d645a9b1a4902ae52602db6270be75f7aa512 (patch) | |
| tree | 2031e0effa15747957246708eda353721db488e8 /src/libstd | |
| parent | 3e90a12a8a95933604a8b609197fce61bb24a38c (diff) | |
| download | rust-f59d645a9b1a4902ae52602db6270be75f7aa512.tar.gz rust-f59d645a9b1a4902ae52602db6270be75f7aa512.zip | |
Defactored Bytes::read
Removed unneeded refactoring of read_one_byte, which removed the unneeded dynamic dispatch (`dyn Read`) used by that function.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/io/mod.rs | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 076524e624a..452cbae4411 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1936,18 +1936,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 +1953,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 buf = [0]; + loop { + return match self.inner.read(&mut buf) { + Err(ref e) if e.kind() == ErrorKind::Interrupted => continue, + Ok(0) => None, + Ok(..) => Some(Ok(buf[0])), + Err(e) => Some(Err(e)), + }; + } } } |
