Skip to content

Commit

Permalink
Rollup merge of rust-lang#37696 - arthurprs:patch-1, r=alexcrichton
Browse files Browse the repository at this point in the history
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 rust-lang#37573
  • Loading branch information
eddyb authored Nov 11, 2016
2 parents 5823693 + dcd80b8 commit 739003f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/libstd/io/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 739003f

Please sign in to comment.