backup/chunk_store.rs: resize buffer by powers of two
This commit is contained in:
parent
9409255aae
commit
060c4811a0
|
@ -178,10 +178,11 @@ impl ChunkStore {
|
||||||
let stat = nix::sys::stat::fstat(f.as_raw_fd())?;
|
let stat = nix::sys::stat::fstat(f.as_raw_fd())?;
|
||||||
let size = stat.st_size as usize;
|
let size = stat.st_size as usize;
|
||||||
|
|
||||||
unsafe { buffer.set_len(buffer.capacity()); }
|
if buffer.capacity() < size {
|
||||||
if buffer.len() < size {
|
let mut newsize = buffer.capacity();
|
||||||
let additional = size - buffer.len();
|
while newsize < size { newsize = newsize << 1; }
|
||||||
buffer.reserve(additional);
|
let additional = newsize - buffer.len();
|
||||||
|
buffer.reserve_exact(additional);
|
||||||
}
|
}
|
||||||
unsafe { buffer.set_len(size); }
|
unsafe { buffer.set_len(size); }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue