From 240734c31e529557583a0dc8e97abf858b4a375d Mon Sep 17 00:00:00 2001 From: bcoopers Date: Mon, 30 Mar 2015 13:59:32 -0400 Subject: [PATCH] Only zero at most 64k at a time. We still use the doubling reallocation strategy since extend() calls reserve() and/or push() for us. --- src/libstd/io/mod.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index c4ec2a7ca17..6b03fb45c77 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -101,18 +101,14 @@ 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 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..]) {