MCPcopy Create free account
hub / github.com/acl-dev/acl / acl_array_grow

Function acl_array_grow

lib_acl/src/stdlib/common/acl_array.c:114–158  ·  view source on GitHub ↗

grows internal buffer to satisfy required minimal capacity */

Source from the content-addressed store, hash-verified

112
113/* grows internal buffer to satisfy required minimal capacity */
114static void acl_array_grow(ACL_ARRAY *a, int min_capacity)
115{
116 int min_delta = 16;
117 int delta;
118
119 /* don't need to grow the capacity of the array */
120 if(a->capacity >= min_capacity)
121 return;
122
123 delta = min_capacity;
124 /* make delta a multiple of min_delta */
125 delta += min_delta - 1;
126 delta /= min_delta;
127 delta *= min_delta;
128 /* actual grow */
129 if (delta <= 0)
130 return;
131
132 a->capacity += delta;
133
134 if (a->items == NULL) {
135 if (a->dbuf == NULL) {
136 a->items = (void**)
137 acl_mymalloc(a->capacity * sizeof(void*));
138 } else {
139 a->items = (void**) acl_dbuf_pool_alloc(a->dbuf,
140 a->capacity * sizeof(void*));
141 }
142 } else if (a->dbuf == NULL) {
143 a->items = (void**) acl_myrealloc(a->items,
144 a->capacity * sizeof(void*));
145 } else if (a->count > 0) {
146 void **old_items = a->items;
147 a->items = (void**) acl_dbuf_pool_calloc(a->dbuf,
148 a->capacity * sizeof(void*));
149 memcpy(a->items, old_items, a->count * sizeof(void*));
150 } else {
151 a->items = (void **) acl_dbuf_pool_calloc(a->dbuf,
152 a->capacity * sizeof(void *));
153 }
154
155 /* reset, just in case */
156 memset(a->items + a->count, 0,
157 (a->capacity - a->count) * sizeof(void *));
158}
159
160ACL_ARRAY *acl_array_create(int init_size)
161{

Callers 4

acl_array_appendFunction · 0.85
acl_array_pred_insertFunction · 0.85
acl_array_succ_insertFunction · 0.85
acl_array_pre_appendFunction · 0.85

Calls 3

acl_dbuf_pool_allocFunction · 0.85
acl_dbuf_pool_callocFunction · 0.85
memcpyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…