[Bf-blender-cvs] [5f267ab] master: BLI_array: add BLI_array_append_ret
Campbell Barton
noreply at git.blender.org
Sun Sep 28 07:09:17 CEST 2014
Commit: 5f267ab9f313a028c0900755608226f34d462b6e
Author: Campbell Barton
Date: Sun Sep 28 13:37:13 2014 +1000
Branches: master
https://developer.blender.org/rB5f267ab9f313a028c0900755608226f34d462b6e
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.
===================================================================
M source/blender/blenlib/BLI_array.h
===================================================================
diff --git a/source/blender/blenlib/BLI_array.h b/source/blender/blenlib/BLI_array.h
index 3a9d013..a1f25a0 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) { \
More information about the Bf-blender-cvs
mailing list