diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-03-14 17:42:44 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-03-14 17:53:20 +0300 |
commit | 342593f1248c739a9f30c005ae710b9b9c7d0877 (patch) | |
tree | ff7e83900ff88ea3bd444b0f2321e436f89e7096 /source/blender/blenlib/BLI_array.h | |
parent | c22c2ff060a27bcd565f84233d2bbfa968b00a3f (diff) |
Cleanup: rename BLI_array_count -> len
Match naming convention used everywhere else.
Count should only be used when this isn't directly accessible.
Diffstat (limited to 'source/blender/blenlib/BLI_array.h')
-rw-r--r-- | source/blender/blenlib/BLI_array.h | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/source/blender/blenlib/BLI_array.h b/source/blender/blenlib/BLI_array.h index 825acb18e91..8e94b8197ef 100644 --- a/source/blender/blenlib/BLI_array.h +++ b/source/blender/blenlib/BLI_array.h @@ -62,9 +62,10 @@ * Doing the realloc in a macro isn't so simple, * so use a function the macros can use. */ -void _bli_array_grow_func(void **arr_p, const void *arr_static, - const int sizeof_arr_p, const int arr_count, const int num, - const char *alloc_str); +void _bli_array_grow_func( + void **arr_p, const void *arr_static, + const int sizeof_arr_p, const int arr_len, const int num, + const char *alloc_str); /* -------------------------------------------------------------------- */ @@ -74,18 +75,18 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static, /** use ``sizeof(*(arr))`` to ensure the array exists and is an array */ #define BLI_array_declare(arr) \ - int _##arr##_count = ((void)(sizeof(*(arr))), 0); \ + int _##arr##_len = ((void)(sizeof(*(arr))), 0); \ void *_##arr##_static = NULL /** * this will use stack space, up to maxstatic array elements, before * switching to dynamic heap allocation */ #define BLI_array_staticdeclare(arr, maxstatic) \ - int _##arr##_count = 0; \ + int _##arr##_len = 0; \ char _##arr##_static[maxstatic * sizeof(*(arr))] /** returns the logical size of the array, not including buffering. */ -#define BLI_array_count(arr) ((void)0, _##arr##_count) +#define BLI_array_len(arr) ((void)0, _##arr##_len) /** * Grow the array by a fixed number of items. @@ -95,23 +96,23 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static, #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))) ? \ + /* don't add _##arr##_len below because it must be zero */ \ + (_bli_array_totalsize_static(arr) >= _##arr##_len + (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##_len + (num)) ? \ (void)0 /* do nothing */ : \ _bli_array_grow_func((void **)&(arr), _##arr##_static, \ - sizeof(*(arr)), _##arr##_count, num, \ + sizeof(*(arr)), _##arr##_len, num, \ "BLI_array." #arr)) \ ) /** returns length of array */ #define BLI_array_grow_items(arr, num) \ - (BLI_array_reserve(arr, num), (_##arr##_count += num)) + (BLI_array_reserve(arr, num), (_##arr##_len += num)) #define BLI_array_grow_one(arr) \ BLI_array_grow_items(arr, 1) @@ -119,7 +120,7 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static, /** appends an item to the array. */ #define BLI_array_append(arr, item) ( \ (void) BLI_array_grow_one(arr), \ - (void) (arr[_##arr##_count - 1] = item) \ + (void) (arr[_##arr##_len - 1] = item) \ ) /** @@ -127,13 +128,13 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static, * item is not a pointer, but actual data value.*/ #define BLI_array_append_r(arr, item) ( \ (void) BLI_array_grow_one(arr), \ - (void) (arr[_##arr##_count - 1] = item), \ - (&arr[_##arr##_count - 1]) \ + (void) (arr[_##arr##_len - 1] = item), \ + (&arr[_##arr##_len - 1]) \ ) /** appends (grows) & returns a pointer to the uninitialized memory */ #define BLI_array_append_ret(arr) \ - (BLI_array_reserve(arr, 1), &arr[(_##arr##_count++)]) + (BLI_array_reserve(arr, 1), &arr[(_##arr##_len++)]) #define BLI_array_free(arr) { \ if (arr && (char *)arr != _##arr##_static) { \ @@ -143,26 +144,26 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static, } ((void)0) #define BLI_array_pop(arr) ( \ - (arr && _##arr##_count) ? \ - arr[--_##arr##_count] : \ + (arr && _##arr##_len) ? \ + arr[--_##arr##_len] : \ NULL \ ) /** - * resets the logical size of an array to zero, but doesn't + * Resets the logical size of an array to zero, but doesn't * free the memory. */ #define BLI_array_clear(arr) \ - { _##arr##_count = 0; } (void)0 + { _##arr##_len = 0; } ((void)0) /** - * set the count of the array, doesn't actually increase the allocated array + * Set the length of the array, doesn't actually increase the allocated array * size. don't use this unless you know what you're doing. */ -#define BLI_array_count_set(arr, count) \ - { _##arr##_count = (count); }(void)0 +#define BLI_array_len_set(arr, len) \ + { _##arr##_len = (len); } ((void)0) /** only to prevent unused warnings */ #define BLI_array_fake_user(arr) \ - ((void)_##arr##_count, \ + ((void)_##arr##_len, \ (void)_##arr##_static) /** \} */ @@ -191,7 +192,7 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static, #define BLI_array_fixedstack_free(arr) \ if (_##arr##_is_static) { \ MEM_freeN(arr); \ - } (void)0 + } ((void)0) /** \} */ |