]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #81136 - Xavientois:io_reader_size_hint, r=cramertj
authorMara <m-ou.se@m-ou.se>
Fri, 5 Mar 2021 09:57:17 +0000 (10:57 +0100)
committerGitHub <noreply@github.com>
Fri, 5 Mar 2021 09:57:17 +0000 (10:57 +0100)
Improved IO Bytes Size Hint

After trying to implement better `size_hint()` return values for `File` in [this PR](https://github.com/rust-lang/rust/pull/81044) and changing to implementing it for `BufReader` in [this PR](https://github.com/rust-lang/rust/pull/81052), I have arrived at this implementation that provides tighter bounds for the `Bytes` iterator of various readers including `BufReader`, `Empty`, and `Chain`.

Unfortunately, for `BufReader`, the size_hint only improves after calling `fill_buffer` due to it using the contents of the buffer for the hint. Nevertheless, the the tighter bounds  should result in better pre-allocation of space to handle the contents of the `Bytes` iterator.

Closes #81052

1  2 
library/std/src/io/mod.rs

Simple merge