Skip to content

Commit

Permalink
close #8269: grow arrays incrementally by factors of 1.5 rather than 2
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed May 10, 2016
1 parent c9d4051 commit eb8a084
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit eb8a084

Please sign in to comment.