Skip to content

Commit

Permalink
Only zero at most 64k at a time. We still use the doubling
Browse files Browse the repository at this point in the history
reallocation strategy since extend() calls reserve() and/or
push() for us.
  • Loading branch information
bcoopers committed Mar 30, 2015
1 parent 8d3e559 commit 240734c
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/libstd/io/mod.rs
Expand Up @@ -101,18 +101,14 @@ 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 min_cap_bump = 16;
let mut new_write_size = 16;
let ret;
loop {
if len == buf.len() {
if buf.capacity() == buf.len() {
// reserve() rounds up our request such that every request
// (with maybe the exception of the first request) for the
// same amount of space doubles our capacity.
buf.reserve(min_cap_bump);
if new_write_size < DEFAULT_BUF_SIZE {
new_write_size *= 2;
}
let new_area = buf.capacity() - buf.len();
buf.extend(iter::repeat(0).take(new_area));
buf.extend(iter::repeat(0).take(new_write_size));
}

match r.read(&mut buf[len..]) {
Expand Down

0 comments on commit 240734c

Please sign in to comment.