]> git.lizzy.rs Git - rust.git/commitdiff
Remove unnecessary `cmp::min` from BufWriter::write
authorRichard Janis Goldschmidt <janis.beckert@gmail.com>
Sun, 11 Sep 2016 14:48:04 +0000 (16:48 +0200)
committerRichard Janis Goldschmidt <janis.beckert@gmail.com>
Sun, 11 Sep 2016 14:48:04 +0000 (16:48 +0200)
The first branch of the if statement already checks if `buf.len() >= self.buf.capacity()`, which makes the `cmp::min(buf.len(), self.buf.capacity())` redundant: the result will always be `buf.len()`. Therefore, we can pass the `buf` slice directly into `Write::write`.

src/libstd/io/buffered.rs

index a26a932ad2de6c076f9d3d0720ce4135802aebf1..dbb45d54f38d185a57a5828d75b6d1927b25c8f0 100644 (file)
@@ -468,8 +468,7 @@ fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
             self.panicked = false;
             r
         } else {
-            let amt = cmp::min(buf.len(), self.buf.capacity());
-            Write::write(&mut self.buf, &buf[..amt])
+            Write::write(&mut self.buf, buf)
         }
     }
     fn flush(&mut self) -> io::Result<()> {