From 1884f6e7296a3847f14331aadd6c520cc25e4d12 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 20 Feb 2022 21:29:00 +1100 Subject: BLI_array: add BLI_array_trim utility to re-allocate the current size Use this in BKE_view_layer_array_* functions. --- source/blender/blenlib/BLI_array.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'source/blender/blenlib') 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) + /** \} */ /* -------------------------------------------------------------------- */ -- cgit v1.2.3