diff options
author | Campbell Barton <campbell@blender.org> | 2022-02-20 13:29:00 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-02-21 04:01:32 +0300 |
commit | 1884f6e7296a3847f14331aadd6c520cc25e4d12 (patch) | |
tree | bdc6a7d2482329f7383f34c399c8915579431a11 /source/blender/blenlib/BLI_array.h | |
parent | 7b11c717294341f5c288e2dc8432e84bc53663ff (diff) |
BLI_array: add BLI_array_trim utility to re-allocate the current size
Use this in BKE_view_layer_array_* functions.
Diffstat (limited to 'source/blender/blenlib/BLI_array.h')
-rw-r--r-- | source/blender/blenlib/BLI_array.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_array.h b/source/blender/blenlib/BLI_array.h index d3bb3401d7e..80e865ded62 100644 --- a/source/blender/blenlib/BLI_array.h +++ b/source/blender/blenlib/BLI_array.h @@ -146,6 +146,17 @@ void _bli_array_grow_func(void **arr_p, */ #define BLI_array_fake_user(arr) ((void)_##arr##_len, (void)_##arr##_static) +/** + * Trim excess items from the array (when they exist). + */ +#define BLI_array_trim(arr) \ + { \ + if (_bli_array_totalsize_dynamic(arr) != _##arr##_len) { \ + arr = MEM_reallocN(arr, sizeof(*arr) * _##arr##_len); \ + } \ + } \ + ((void)0) + /** \} */ /* -------------------------------------------------------------------- */ |