Skip to content

Commit

Permalink
Change read_to_end to read at least the buffer's capacity.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Mark-Simulacrum committed Aug 20, 2016
1 parent 499484f commit a21c7b5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,11 @@ fn append_to_string<F>(buf: &mut String, f: F) -> Result<usize>
fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize> {
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() {
Expand Down

0 comments on commit a21c7b5

Please sign in to comment.