From bfe9fa117ed3070e46e75fd8f4e339368af17d5e Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sun, 18 Nov 2018 10:13:04 -0800 Subject: 4750 There can be situations where a run is striding through a segment. Reduce the number of reallocations that reallocations that requires. --- subx/010---vm.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/subx/010---vm.cc b/subx/010---vm.cc index 24051ec4..47b2c3da 100644 --- a/subx/010---vm.cc +++ b/subx/010---vm.cc @@ -139,6 +139,10 @@ struct vma { #define align_upwards(x, align) (((x)+(align)-1) & -(align)) uint32_t new_size = align_upwards(result_size, align); #undef align_upwards + // grow at least 2x to maintain some amortized complexity guarantees + if (new_size < _data.size() * 2) + new_size = _data.size() * 2; + // never grow past the stated limit if (new_size > end-start) new_size = end-start; _data.resize(new_size); -- cgit 1.4.1-2-gfad0