diff options
| author | bcoopers <coopersmithbrian@gmail.com> | 2015-03-30 13:59:32 -0400 |
|---|---|---|
| committer | bcoopers <coopersmithbrian@gmail.com> | 2015-03-30 13:59:32 -0400 |
| commit | 240734c31e529557583a0dc8e97abf858b4a375d (patch) | |
| tree | 0136110c2215ddf3e32ce737076d98249d773e0f | |
| parent | 8d3e55908ae0e51f04c170133c9f9739886b8e2e (diff) | |
| download | rust-240734c31e529557583a0dc8e97abf858b4a375d.tar.gz rust-240734c31e529557583a0dc8e97abf858b4a375d.zip | |
Only zero at most 64k at a time. We still use the doubling
reallocation strategy since extend() calls reserve() and/or push() for us.
| -rw-r--r-- | src/libstd/io/mod.rs | 12 |
1 files 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<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..]) { |
