diff options
Diffstat (limited to 'source/blender/blenlib/BLI_array.h')
-rw-r--r-- | source/blender/blenlib/BLI_array.h | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/source/blender/blenlib/BLI_array.h b/source/blender/blenlib/BLI_array.h index 3a9d013f796..db33c5cec8b 100644 --- a/source/blender/blenlib/BLI_array.h +++ b/source/blender/blenlib/BLI_array.h @@ -84,26 +84,30 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static, * * Allow for a large 'num' value when the new size is more than double * to allocate the exact sized array. */ -#define BLI_array_grow_items(arr, num) (( \ +#define BLI_array_reserve(arr, num) (void)( \ (((void *)(arr) == NULL) && \ ((void *)(_##arr##_static) != NULL) && \ /* don't add _##arr##_count below because it must be zero */ \ - (_bli_array_totalsize_static(arr) >= _##arr##_count + num)) ? \ + (_bli_array_totalsize_static(arr) >= _##arr##_count + (num))) ? \ /* we have an empty array and a static var big enough */ \ (void)(arr = (void *)_##arr##_static) \ : \ /* use existing static array or allocate */ \ - (LIKELY(_bli_array_totalsize(arr) >= _##arr##_count + num) ? \ + (LIKELY(_bli_array_totalsize(arr) >= _##arr##_count + (num)) ? \ (void)0 /* do nothing */ : \ _bli_array_grow_func((void **)&(arr), _##arr##_static, \ sizeof(*(arr)), _##arr##_count, num, \ "BLI_array." #arr)) \ - ), \ - /* increment the array count, all conditions above are accounted for. */ \ - (_##arr##_count += num)) + ) + /* returns length of array */ -#define BLI_array_grow_one(arr) BLI_array_grow_items(arr, 1) + +#define BLI_array_grow_items(arr, num) \ + (BLI_array_reserve(arr, num), (_##arr##_count += num)) + +#define BLI_array_grow_one(arr) \ + BLI_array_grow_items(arr, 1) /* appends an item to the array. */ @@ -120,9 +124,9 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static, (&arr[_##arr##_count - 1]) \ ) -#define BLI_array_reserve(arr, num) \ - BLI_array_grow_items(arr, num), (void)(_##arr##_count -= (num)) - +/* appends (grows) & returns a pointer to the uninitialized memory */ +#define BLI_array_append_ret(arr) \ + (BLI_array_reserve(arr, 1), &arr[(_##arr##_count++)]) #define BLI_array_free(arr) \ if (arr && (char *)arr != _##arr##_static) { \ |