diff options
| author | Arthur Silva <arthurprs@gmail.com> | 2016-11-10 22:02:44 +0100 |
|---|---|---|
| committer | arthurprs <arthurprs@gmail.com> | 2016-11-10 22:26:50 +0100 |
| commit | dcd80b80ae3fe2f327515e57fdc423a3927e44e6 (patch) | |
| tree | 1f599f714118892c6a7807debe72001f1de9a269 /src/libstd/io | |
| parent | bc1cc1db6ddee8d57d20adc05b740e3b73649ab5 (diff) | |
| download | rust-dcd80b80ae3fe2f327515e57fdc423a3927e44e6.tar.gz rust-dcd80b80ae3fe2f327515e57fdc423a3927e44e6.zip | |
Remove one bounds check from BufReader
Otherwise the optimizer can't be sure that pos <= cap. Added a paranoid debug_assert to ensure correctness instead.
Diffstat (limited to 'src/libstd/io')
| -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; } |
