Skip to content

Commit a21c7b5

Browse files
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.
1 parent 499484f commit a21c7b5

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/libstd/io/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,11 @@ fn append_to_string<F>(buf: &mut String, f: F) -> Result<usize>
345345
fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize> {
346346
let start_len = buf.len();
347347
let mut len = start_len;
348-
let mut new_write_size = 16;
348+
let mut new_write_size = if buf.capacity() > 16 {
349+
buf.capacity() - buf.len()
350+
} else {
351+
16
352+
};
349353
let ret;
350354
loop {
351355
if len == buf.len() {

0 commit comments

Comments
 (0)