# HG changeset patch # User Mike Becker # Date 1762537326 -3600 # Node ID 79d4c281a63b4dff09c63260d1a25888b94a6307 # Parent 9381883c1a99edca71daae7587a2b90cb43f1d10 add documentation for cx_array_align_capacity() and use it in cx_arl_insert_array() diff -r 9381883c1a99 -r 79d4c281a63b src/array_list.c --- a/src/array_list.c Fri Nov 07 18:08:41 2025 +0100 +++ b/src/array_list.c Fri Nov 07 18:42:06 2025 +0100 @@ -102,6 +102,14 @@ // LOW LEVEL ARRAY LIST FUNCTIONS +/** + * Increases the capacity until it is a multiple of a some alignment or reaches the maximum. + * + * @param cap the required capacity (must not be larger than @p max) + * @param alignment the alignment + * @param max the maximum capacity + * @return the aligned capacity + */ static size_t cx_array_align_capacity( size_t cap, size_t alignment, @@ -782,7 +790,7 @@ // guarantee enough capacity if (arl->capacity < list->collection.size + n) { size_t new_capacity = list->collection.size + n; - new_capacity = new_capacity - (new_capacity % 16) + 16; + new_capacity = cx_array_align_capacity(new_capacity, 16, SIZE_MAX); if (cxReallocateArray( list->collection.allocator, &arl->data, new_capacity,