diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-08-04 14:22:58 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-08-04 14:22:58 -0400 |
| commit | ff4ea60daf8a97d07a5b0419c05441d7312a1901 (patch) | |
| tree | 3bb7f991ae7bbe4ad3a703c5df09c0d5625b19ca /builtins/array.h | |
| parent | adccc5688062271ca6999a15d6c09bd106462704 (diff) | |
Tweaks to array implementation, including changing how the bits are
allocated, making more explicit checks for refcounts and max values,
optimizations for certain methods, and adding compile-time errors for
arrays that hold items that are too large.
Diffstat (limited to 'builtins/array.h')
| -rw-r--r-- | builtins/array.h | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/builtins/array.h b/builtins/array.h index 6d5c3015..cefea807 100644 --- a/builtins/array.h +++ b/builtins/array.h @@ -49,8 +49,9 @@ .data=memcpy(is_atomic(x) ? GC_MALLOC_ATOMIC(sizeof(items)) : GC_MALLOC(sizeof(items)), items, sizeof(items)), \ .atomic=is_atomic(x), \ .data_refcount=1}; }) -#define ARRAY_INCREF(arr) (arr).data_refcount |= ((arr).data_refcount << 1) | 1 -#define ARRAY_DECREF(arr) (arr).data_refcount &= 2 +// Array refcounts use a saturating add, where once it's at the max value, it stays there. +#define ARRAY_INCREF(arr) (arr).data_refcount += ((arr).data_refcount < ARRAY_MAX_DATA_REFCOUNT) +#define ARRAY_DECREF(arr) (arr).data_refcount -= ((arr).data_refcount < ARRAY_MAX_DATA_REFCOUNT) #define Array$insert_value(arr, item_expr, index, padded_item_size) ({ __typeof(item_expr) item = item_expr; Array$insert(arr, &item, index, padded_item_size); }) void Array$insert(array_t *arr, const void *item, int64_t index, int64_t padded_item_size); |
