From a21c7b5b92cd1afe6ceea479083a8c45baff7fd8 Mon Sep 17 00:00:00 2001 From: Mark-Simulacrum Date: Fri, 19 Aug 2016 19:40:00 -0600 Subject: [PATCH] Change read_to_end to read at least the buffer's capacity. The buffer's capacity or 16 bytes, whichever is larger, is the minimum start read size, but it will get twice as large with each read. --- src/libstd/io/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 88fd4186e0a2a..e205cb6f18dbc 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -345,7 +345,11 @@ fn append_to_string(buf: &mut String, f: F) -> Result fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { let start_len = buf.len(); let mut len = start_len; - let mut new_write_size = 16; + let mut new_write_size = if buf.capacity() > 16 { + buf.capacity() - buf.len() + } else { + 16 + }; let ret; loop { if len == buf.len() {