Only zero at most 64k at a time. We still use the doubling
reallocation strategy since extend() calls reserve() and/or push() for us.
This commit is contained in:
parent
8d3e55908a
commit
240734c31e
@ -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..]) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user