From eb8a084c1f0db62aa331a04fcf17f3b5af700316 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Tue, 10 May 2016 19:36:33 -0400 Subject: [PATCH] close #8269: grow arrays incrementally by factors of 1.5 rather than 2 --- src/array.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/array.c b/src/array.c index 2e81e21e8308b2..e6d531bde4b608 100644 --- a/src/array.c +++ b/src/array.c @@ -631,9 +631,9 @@ JL_DLLEXPORT void jl_array_grow_end(jl_array_t *a, size_t inc) // optimized for the case of only growing and shrinking at the end size_t alen = jl_array_nrows(a); if ((alen + inc) > a->maxsize - a->offset) { - size_t newlen = a->maxsize==0 ? (inc<4?4:inc) : a->maxsize*2; + size_t newlen = a->maxsize < 2 ? (inc<4?4:inc) : (a->maxsize*3)>>1; while ((alen + inc) > newlen - a->offset) - newlen *= 2; + newlen = (newlen*3)>>1; newlen = limit_overallocation(a, alen, newlen, inc); array_resize_buffer(a, newlen, alen, a->offset); @@ -692,9 +692,9 @@ JL_DLLEXPORT void jl_array_grow_beg(jl_array_t *a, size_t inc) size_t alen = a->nrows; size_t anb = alen*es; if (inc > (a->maxsize-alen)/2 - (a->maxsize-alen)/20) { - size_t newlen = a->maxsize==0 ? inc*2 : a->maxsize*2; + size_t newlen = a->maxsize < 2 ? inc*2 : (a->maxsize*3)>>1; while (alen+2*inc > newlen-a->offset) - newlen *= 2; + newlen = (newlen*3)>>1; newlen = limit_overallocation(a, alen, newlen, 2*inc); size_t center = (newlen - (alen + inc))/2;