grows internal buffer to satisfy required minimal capacity */
| 112 | |
| 113 | /* grows internal buffer to satisfy required minimal capacity */ |
| 114 | static 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 | |
| 147 | ARRAY *array_create(int init_size, unsigned flags) |
| 148 | { |
no test coverage detected
searching dependent graphs…