Files
rust/src/libstd
Mazdak Farrokhzad a5299dd5d1 Rollup merge of #63216 - oconnor663:take_read_to_end, r=sfackler
avoid unnecessary reservations in std::io::Take::read_to_end

Prevously the `read_to_end` implementation for `std::io::Take` used its
own `limit` as a cap on the `reservation_size`. However, that could
still result in an over-allocation like this:

1. Call `reader.take(5).read_to_end(&mut vec)`.
2. `read_to_end_with_reservation` reserves 5 bytes and calls `read`.
3. `read` writes 5 bytes.
4. `read_to_end_with_reservation` reserves 5 bytes and calls `read`.
5. `read` writes 0 bytes.
6. The read loop ends with `vec` having length 5 and capacity 10.

The reservation of 5 bytes was correct for the read at step 2 but
unnecessary for the read at step 4. By that second read, `Take::limit`
is 0, but the `read_to_end_with_reservation` loop is still using the
same `reservation_size` it started with.

Solve this by having `read_to_end_with_reservation` take a closure,
which lets it get a fresh `reservation_size` for each read. This is an
implementation detail which doesn't affect any public API.
2019-08-20 16:26:34 +02:00
..
2019-08-14 05:39:53 -04:00
2019-08-15 22:58:57 +03:00
2019-08-14 05:39:53 -04:00
2019-02-28 04:06:15 +09:00
2018-12-25 21:08:33 -07:00
2019-08-11 12:49:02 +01:00
2019-08-15 22:58:57 +03:00
2019-02-28 04:06:15 +09:00
2019-04-23 00:15:43 +02:00
2019-07-02 16:01:06 +02:00
2019-07-01 20:21:12 -07:00
2019-02-28 04:06:15 +09:00