]> git.lizzy.rs Git - rust.git/commitdiff
Defactored Bytes::read
authorNathan West <Lucretiel@users.noreply.github.com>
Fri, 30 Nov 2018 01:36:32 +0000 (20:36 -0500)
committerGitHub <noreply@github.com>
Fri, 30 Nov 2018 01:36:32 +0000 (20:36 -0500)
Removed unneeded refactoring of read_one_byte, which removed the unneeded dynamic dispatch (`dyn Read`) used by that function.

src/libstd/io/mod.rs

index 076524e624a4781af978d112a7455243337a111b..452cbae4411d6fa8e9d5c04210d82b7210c0c743 100644 (file)
@@ -1936,18 +1936,6 @@ fn consume(&mut self, amt: usize) {
     }
 }
 
-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)),
+            };
+        }
     }
 }