Skip to content

Commit d6aa4e8

Browse files
Rollup merge of #36397 - SuperFluffy:bufwriter_unnecessary_cmp, r=aturon
Remove unnecessary `cmp::min` from BufWriter::write 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`.
2 parents 2a88e6c + c8b656b commit d6aa4e8

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/libstd/io/buffered.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,7 @@ impl<W: Write> Write for BufWriter<W> {
468468
self.panicked = false;
469469
r
470470
} else {
471-
let amt = cmp::min(buf.len(), self.buf.capacity());
472-
Write::write(&mut self.buf, &buf[..amt])
471+
Write::write(&mut self.buf, buf)
473472
}
474473
}
475474
fn flush(&mut self) -> io::Result<()> {

0 commit comments

Comments
 (0)