diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-12-07 15:59:37 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-12-07 15:59:37 -0500 |
| commit | a201939a8150bc4c2f221925797ea2751c74b77c (patch) | |
| tree | 26fee4ec601319fd8771435087931023e393fe92 /stdlib/arrays.h | |
| parent | 683b0f5141ad21914d77cd4b4b81e7e2161f90f3 (diff) | |
Use likely()/unlikely() macros and a few bugfixes for integers
Diffstat (limited to 'stdlib/arrays.h')
| -rw-r--r-- | stdlib/arrays.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/stdlib/arrays.h b/stdlib/arrays.h index 4f7161bd..e880c643 100644 --- a/stdlib/arrays.h +++ b/stdlib/arrays.h @@ -13,7 +13,7 @@ #define Array_get(item_type, arr_expr, index_expr, start, end) *({ \ const Array_t arr = arr_expr; int64_t index = index_expr; \ int64_t off = index + (index < 0) * (arr.length + 1) - 1; \ - if (__builtin_expect(off < 0 || off >= arr.length, 0)) \ + if (unlikely(off < 0 || off >= arr.length)) \ fail_source(__SOURCE_FILE__, start, end, "Invalid array index: %s (array has length %ld)\n", Text$as_c_string(Int64$as_text(&index, no, NULL)), arr.length); \ (item_type*)(arr.data + arr.stride * off);}) #define Array_get_unchecked(type, x, i) *({ const Array_t arr = x; int64_t index = i; \ @@ -22,7 +22,7 @@ #define Array_lvalue(item_type, arr_expr, index_expr, padded_item_size, start, end) *({ \ Array_t *arr = arr_expr; int64_t index = index_expr; \ int64_t off = index + (index < 0) * (arr->length + 1) - 1; \ - if (__builtin_expect(off < 0 || off >= arr->length, 0)) \ + if (unlikely(off < 0 || off >= arr->length)) \ fail_source(__SOURCE_FILE__, start, end, "Invalid array index: %s (array has length %ld)\n", Text$as_c_string(Int64$as_text(&index, no, NULL)), arr->length); \ if (arr->data_refcount > 0) \ Array$compact(arr, padded_item_size); \ |
