grows internal buffer to satisfy required minimal capacity */
| 112 | |
| 113 | /* grows internal buffer to satisfy required minimal capacity */ |
| 114 | static 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 | |
| 160 | ACL_ARRAY *acl_array_create(int init_size) |
| 161 | { |
no test coverage detected
searching dependent graphs…