From dd632cfe55ad300e8b8c23463791a1433ccb4e27 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Fri, 29 Apr 2016 16:15:24 -0400 Subject: [PATCH] lib/core: Improve FlatBuffer re-allocation rate by pre-allocating at least 16 bytes Signed-off-by: Lucas Bajolet --- lib/core/text/flat.nit | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/core/text/flat.nit b/lib/core/text/flat.nit index 0fc5663..2533323 100644 --- a/lib/core/text/flat.nit +++ b/lib/core/text/flat.nit @@ -933,12 +933,13 @@ class FlatBuffer do var c = capacity if cap <= c then return - while c <= cap do c = c * 2 + 2 + if c <= 16 then c = 16 + while c <= cap do c = c * 2 # The COW flag can be set at false here, since # it does a copy of the current `Buffer` written = false var bln = _bytelen - var a = new NativeString(c+1) + var a = new NativeString(c) if bln > 0 then var it = _items if bln > 0 then it.copy_to(a, bln, 0, 0) -- 1.7.9.5