Skip to content

Commit 739003f

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#37573
2 parents 5823693 + dcd80b8 commit 739003f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/libstd/io/buffered.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ impl<R: Read> BufRead for BufReader<R> {
187187
fn fill_buf(&mut self) -> io::Result<&[u8]> {
188188
// If we've reached the end of our internal buffer then we need to fetch
189189
// some more data from the underlying reader.
190-
if self.pos == self.cap {
190+
// Branch using `>=` instead of the more correct `==`
191+
// to tell the compiler that the pos..cap slice is always valid.
192+
if self.pos >= self.cap {
193+
debug_assert!(self.pos == self.cap);
191194
self.cap = self.inner.read(&mut self.buf)?;
192195
self.pos = 0;
193196
}

0 commit comments

Comments
 (0)