summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--courgette/memory_allocator.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/courgette/memory_allocator.h b/courgette/memory_allocator.h
index 5386dad..ada7f40 100644
--- a/courgette/memory_allocator.h
+++ b/courgette/memory_allocator.h
@@ -333,6 +333,12 @@ class NoThrowBuffer {
if (size < kStartSize)
size = kStartSize;
+ // Use a size 1% higher than requested. In practice, this makes Courgette as
+ // much as 5x faster on typical Chrome update payloads as a lot of future
+ // reserve() calls will become no-ops instead of costly resizes that copy
+ // all the data. Note that doing this here instead of outside the function
+ // is more efficient, since it's after the no-op early return checks above.
+ size *= 1.01;
T* new_buffer = alloc_.allocate(size);
if (!new_buffer) {
clear();