add documentation for cx_array_align_capacity() and use it in cx_arl_insert_array()

Fri, 07 Nov 2025 18:42:06 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 07 Nov 2025 18:42:06 +0100
changeset 1476
79d4c281a63b
parent 1475
9381883c1a99
child 1477
9170a7dff573

add documentation for cx_array_align_capacity() and use it in cx_arl_insert_array()

src/array_list.c file | annotate | diff | comparison | revisions
--- 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,

mercurial