perf: Use same reallocation strategy as Vec

This change seems to improve performance on some benchmarks (e.g.
techempower), but causes performance regression on another benchmark. We
need to measure performance using more test cases.
This commit is contained in:
Kogia-sima 2021-02-03 00:50:24 +09:00
parent 67f49bdd18
commit 47818c11b7
1 changed files with 1 additions and 2 deletions

View File

@ -162,11 +162,10 @@ impl Buffer {
}
#[cfg_attr(feature = "perf-inline", inline)]
#[cold]
fn reserve_internal(&mut self, size: usize) {
debug_assert!(size <= std::isize::MAX as usize);
let new_capacity = std::cmp::max(self.capacity * 2, self.capacity + size);
let new_capacity = std::cmp::max(self.capacity * 2, self.len + size);
debug_assert!(new_capacity > self.capacity);
self.data = unsafe { safe_realloc(self.data, self.capacity, new_capacity) };
self.capacity = new_capacity;