#[doc(hidden)]pub fn default_read_to_end<R: Read + ?Sized>(
r: &mut R,
buf: &mut Vec<u8>,
size_hint: Option<usize>,
) -> Result<usize>🔬This is a nightly-only experimental API. (
core_io_internals)Expand description
Here we must serve many masters with conflicting goals:
- avoid allocating unless necessary
- avoid overallocating if we know the exact size (#89165)
- avoid passing large buffers to readers that always initialize the free capacity if they perform short reads (#23815, #23820)
- avoid re-initializing unfilled bytes into the spare buffer if we initialized >PROBE_SIZE unfilled bytes in a previous loop (#158008)
- pass large buffers to readers that do not initialize the spare capacity. this can amortize per-call overheads
- pass not-too-small and not-too-large buffers to Windows read APIs because they manage to suffer from both problems at the same time, i.e. small reads suffer from syscall overhead, all reads incur costs proportional to buffer size (#110650)
- also avoid <4 byte reads as this may split UTF-8 code points, which can be a problem for Windows console reads (#142847)