diff options
Diffstat (limited to 'source/blender/blenlib/BLI_array.h')
-rw-r--r-- | source/blender/blenlib/BLI_array.h | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/source/blender/blenlib/BLI_array.h b/source/blender/blenlib/BLI_array.h index 3a9d013f796..a1f25a0208a 100644 --- a/source/blender/blenlib/BLI_array.h +++ b/source/blender/blenlib/BLI_array.h @@ -84,7 +84,7 @@ 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 */ \ @@ -98,12 +98,16 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static, _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 += 1)]) #define BLI_array_free(arr) \ if (arr && (char *)arr != _##arr##_static) { \ |