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.
This commit is contained in:
parent
a4c3b92294
commit
5f267ab9f3
|
@ -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) { \
|
||||
|
|
Loading…
Reference in New Issue