From cb44b0971566eaaf78e5095c36a1b3fe61f2f2df Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 4 Aug 2024 14:58:09 -0400 Subject: Tweak reallocation heuristics for arrays --- builtins/array.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'builtins/array.c') diff --git a/builtins/array.c b/builtins/array.c index cd326405..fe1712e7 100644 --- a/builtins/array.c +++ b/builtins/array.c @@ -59,7 +59,7 @@ public void Array$insert(array_t *arr, const void *item, int64_t index, int64_t arr->data = arr->atomic ? GC_MALLOC_ATOMIC(arr->free * padded_item_size) : GC_MALLOC(arr->free * padded_item_size); arr->stride = padded_item_size; } else if (arr->free < 1 || arr->data_refcount != 0 || (int64_t)arr->stride != padded_item_size) { - arr->free = MAX(ARRAY_MAX_FREE_ENTRIES, MIN(1, arr->length/4)); + arr->free = MIN(ARRAY_MAX_FREE_ENTRIES, MAX(8, arr->length/4)); void *copy = arr->atomic ? GC_MALLOC_ATOMIC((arr->length + arr->free) * padded_item_size) : GC_MALLOC((arr->length + arr->free) * padded_item_size); for (int64_t i = 0; i < index-1; i++) memcpy(copy + i*padded_item_size, arr->data + arr->stride*i, padded_item_size); @@ -110,7 +110,7 @@ public void Array$insert_all(array_t *arr, array_t to_insert, int64_t index, int } else { // Otherwise, allocate a new chunk of memory for the array and populate it: int64_t new_len = arr->length + to_insert.length; - arr->free = MAX(ARRAY_MAX_FREE_ENTRIES, MIN(1, new_len/4)); + arr->free = MIN(ARRAY_MAX_FREE_ENTRIES, MAX(8, new_len/4)); void *data = arr->atomic ? GC_MALLOC_ATOMIC((new_len + arr->free) * padded_item_size) : GC_MALLOC((new_len + arr->free) * padded_item_size); void *p = data; -- cgit v1.2.3