Skip to content

Commit f0de1ef

Browse files
committed
close #8269: grow arrays incrementally by factors of 1.5 rather than 2
1 parent 4ef8313 commit f0de1ef

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/array.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -897,11 +897,12 @@ STATIC_INLINE void jl_array_grow_at_end(jl_array_t *a, size_t idx,
897897
if (__unlikely(reqmaxsize > a->maxsize)) {
898898
size_t nb1 = idx * elsz;
899899
size_t nbinc = inc * elsz;
900-
// if the requested size is more than 2x current maxsize, grow exactly
901-
// otherwise double the maxsize
902-
size_t newmaxsize = reqmaxsize >= a->maxsize * 2
900+
// if the requested size is more than 1.5x current maxsize, grow exactly
901+
// otherwise use 1.5x the maxsize
902+
size_t growmaxsize = (a->maxsize*3)>>1;
903+
size_t newmaxsize = reqmaxsize >= growmaxsize
903904
? (reqmaxsize < 4 ? 4 : reqmaxsize)
904-
: a->maxsize * 2;
905+
: growmaxsize;
905906
newmaxsize = limit_overallocation(a, n, newmaxsize, inc);
906907
size_t oldmaxsize = a->maxsize;
907908
int newbuf = array_resize_buffer(a, newmaxsize);

0 commit comments

Comments
 (0)