diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-09-28 07:37:13 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-09-28 09:08:54 +0400 |
commit | 5f267ab9f313a028c0900755608226f34d462b6e (patch) | |
tree | 28050bc974c6702e8bc5ccb69c409547d938ef3b | |
parent | a4c3b9229448e93f10a7706800822b1e0119c033 (diff) |
BLI_array: add BLI_array_append_ret
returns the newly appended item.
also make make it so reserve doesn't have to grow then shrink the array size.
-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) { \ |