diff options
| author | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2016-11-12 10:38:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-11-12 10:38:42 +0200 |
| commit | 8886eccdf7ff704acf664ab875c3c71e74cca1ed (patch) | |
| tree | f1aef1a1329e6f321cdd7f6703050961393fdf7e | |
| parent | 048daa62246abc5dd441c34ffd2834cb6e173060 (diff) | |
| parent | dcd80b80ae3fe2f327515e57fdc423a3927e44e6 (diff) | |
| download | rust-8886eccdf7ff704acf664ab875c3c71e74cca1ed.tar.gz rust-8886eccdf7ff704acf664ab875c3c71e74cca1ed.zip | |
Rollup merge of #37696 - arthurprs:patch-1, r=alexcrichton
Remove one bounds check from BufReader Very minor thing. Otherwise the optimizer can't be sure that pos <= cap. Added a paranoid debug_assert to ensure correctness instead. CC #37573
| -rw-r--r-- | src/libstd/io/buffered.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 44dd4e9874a..cd7a50d07e2 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -187,7 +187,10 @@ impl<R: Read> BufRead for BufReader<R> { fn fill_buf(&mut self) -> io::Result<&[u8]> { // If we've reached the end of our internal buffer then we need to fetch // some more data from the underlying reader. - if self.pos == self.cap { + // Branch using `>=` instead of the more correct `==` + // to tell the compiler that the pos..cap slice is always valid. + if self.pos >= self.cap { + debug_assert!(self.pos == self.cap); self.cap = self.inner.read(&mut self.buf)?; self.pos = 0; } |
