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

Function array_grow

lib_fiber/c/src/common/array.c:114–145  ·  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 array_grow(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
124 delta = min_capacity;
125 /* make delta a multiple of min_delta */
126 delta += min_delta - 1;
127 delta /= min_delta;
128 delta *= min_delta;
129 /* actual grow */
130 if (delta <= 0) {
131 return;
132 }
133
134 a->capacity += delta;
135
136 if (a->items == NULL) {
137 a->items = (void**) mem_malloc(a->capacity * sizeof(void*));
138 } else {
139 a->items = (void**) mem_realloc(a->items, a->capacity * sizeof(void*));
140 }
141
142 /* reset, just in case */
143 memset(a->items + a->count, 0,
144 (a->capacity - a->count) * sizeof(void *));
145}
146
147ARRAY *array_create(int init_size, unsigned flags)
148{

Callers 4

array_appendFunction · 0.85
array_pred_insertFunction · 0.85
array_succ_insertFunction · 0.85
array_pre_appendFunction · 0.85

Calls 2

mem_mallocFunction · 0.85
mem_reallocFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…