backup/chunk_store.rs: resize buffer by powers of two

This commit is contained in:
Dietmar Maurer 2019-01-05 11:34:15 +01:00
parent 9409255aae
commit 060c4811a0
1 changed files with 5 additions and 4 deletions

View File

@ -178,10 +178,11 @@ impl ChunkStore {
let stat = nix::sys::stat::fstat(f.as_raw_fd())?;
let size = stat.st_size as usize;
unsafe { buffer.set_len(buffer.capacity()); }
if buffer.len() < size {
let additional = size - buffer.len();
buffer.reserve(additional);
if buffer.capacity() < size {
let mut newsize = buffer.capacity();
while newsize < size { newsize = newsize << 1; }
let additional = newsize - buffer.len();
buffer.reserve_exact(additional);
}
unsafe { buffer.set_len(size); }