about summary refs log tree commit diff stats
path: root/subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-11-18 10:13:04 -0800
committerKartik Agaram <vc@akkartik.com>2018-11-18 10:13:04 -0800
commitbfe9fa117ed3070e46e75fd8f4e339368af17d5e (patch)
tree7e7c77509aa1d220fbb7e3a0124de1e9ba100677 /subx
parentcfaac2a8ab3e962f04a61ec84d806904641fe441 (diff)
downloadmu-bfe9fa117ed3070e46e75fd8f4e339368af17d5e.tar.gz
4750
There can be situations where a run is striding through a segment. Reduce
the number of reallocations that reallocations that requires.
Diffstat (limited to 'subx')
-rw-r--r--subx/010---vm.cc4
1 files changed, 4 insertions, 0 deletions
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);