diff options
Diffstat (limited to 'source/blender/blenlib/intern/BLI_array.c')
-rw-r--r-- | source/blender/blenlib/intern/BLI_array.c | 78 |
1 files changed, 10 insertions, 68 deletions
diff --git a/source/blender/blenlib/intern/BLI_array.c b/source/blender/blenlib/intern/BLI_array.c index da2eef8ab6a..f681d222e69 100644 --- a/source/blender/blenlib/intern/BLI_array.c +++ b/source/blender/blenlib/intern/BLI_array.c @@ -30,19 +30,14 @@ * \ingroup bli * \brief A (mainly) macro array library. * - * This library needs to be changed to not use macros quite so heavily, - * and to be more of a complete array API. The way arrays are - * exposed to client code as normal C arrays is very useful though, imho. - * it does require some use of macros, however. + * This is an array library, used to manage array (re)allocation. * - * anyway, it's used a bit too heavily to simply rewrite as a - * more "correct" solution without macros entirely. I originally wrote this - * to be very easy to use, without the normal pain of most array libraries. - * This was especially helpful when it came to the massive refactors necessary - * for bmesh, and really helped to speed the process up. - joeedh + * \note This is primarily accessed via macros, + * functions are used to implement some of the internals. * - * little array macro library. example of usage: + * Example usage: * + * \code{.c} * int *arr = NULL; * BLI_array_declare(arr); * int i; @@ -52,20 +47,19 @@ * arr[i] = something; * } * BLI_array_free(arr); + * \endcode * - * arrays are buffered, using double-buffering (so on each reallocation, - * the array size is doubled). supposedly this should give good Big Oh - * behavior, though it may not be the best in practice. + * Arrays are over allocated, so each reallocation the array size is doubled. + * In situations where contiguous array access isn't needed, + * other solutions for allocation are available. + * Consider using on of: BLI_memarena.c, BLI_mempool.c, BLi_stack.c */ #include <string.h> -#include <stdlib.h> #include "BLI_array.h" #include "BLI_sys_types.h" -#include "BLI_utildefines.h" -#include "BLI_alloca.h" #include "MEM_guardedalloc.h" @@ -100,55 +94,3 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static, arr_count += num; #endif } - -void _bli_array_reverse(void *arr_v, unsigned int arr_len, size_t arr_stride) -{ - const unsigned int arr_half_stride = (arr_len / 2) * arr_stride; - unsigned int i, i_end; - char *arr = arr_v; - char *buf = BLI_array_alloca(buf, arr_stride); - - for (i = 0, i_end = (arr_len - 1) * arr_stride; - i < arr_half_stride; - i += arr_stride, i_end -= arr_stride) - { - memcpy(buf, &arr[i], arr_stride); - memcpy(&arr[i], &arr[i_end], arr_stride); - memcpy(&arr[i_end], buf, arr_stride); - } -} - -void _bli_array_wrap(void *arr_v, unsigned int arr_len, size_t arr_stride, int dir) -{ - char *arr = arr_v; - char *buf = BLI_array_alloca(buf, arr_stride); - - if (dir == -1) { - memcpy(buf, arr, arr_stride); - memmove(arr, arr + arr_stride, arr_stride * (arr_len - 1)); - memcpy(arr + (arr_stride * (arr_len - 1)), buf, arr_stride); - } - else if (dir == 1) { - memcpy(buf, arr + (arr_stride * (arr_len - 1)), arr_stride); - memmove(arr + arr_stride, arr, arr_stride * (arr_len - 1)); - memcpy(arr, buf, arr_stride); - } - else { - BLI_assert(0); - } -} - -/** - * \note Not efficient, use for error checks/asserts. - */ -int _bli_array_findindex(const void *arr, unsigned int arr_len, size_t arr_stride, const void *p) -{ - const char *arr_step = (const char *)arr; - unsigned int i; - for (i = 0; i < arr_len; i++, arr_step += arr_stride) { - if (memcmp(arr_step, p, arr_stride) == 0) { - return (int)i; - } - } - return -1; -} |