src/array_list.c

changeset 1047
40aad3f0bc9e
parent 1040
1ecf4dbbc60c
equal deleted inserted replaced
1046:fe2c842fce4b 1047:40aad3f0bc9e
130 130
131 // determine size and capacity 131 // determine size and capacity
132 size_t oldcap; 132 size_t oldcap;
133 size_t oldsize; 133 size_t oldsize;
134 size_t max_size; 134 size_t max_size;
135 if (width == 0 || width == CX_WORDSIZE) { 135 if (width == 0 || width == 8*sizeof(size_t)) {
136 oldcap = *(size_t*) capacity; 136 oldcap = *(size_t*) capacity;
137 oldsize = *(size_t*) size; 137 oldsize = *(size_t*) size;
138 max_size = SIZE_MAX; 138 max_size = SIZE_MAX;
139 } else if (width == 16) { 139 } else if (width == 16) {
140 oldcap = *(uint16_t*) capacity; 140 oldcap = *(uint16_t*) capacity;
184 184
185 // store new pointer 185 // store new pointer
186 *array = newmem; 186 *array = newmem;
187 187
188 // store new capacity 188 // store new capacity
189 if (width == 0 || width == CX_WORDSIZE) { 189 if (width == 0 || width == 8*sizeof(size_t)) {
190 *(size_t*) capacity = newcap; 190 *(size_t*) capacity = newcap;
191 } else if (width == 16) { 191 } else if (width == 16) {
192 *(uint16_t*) capacity = (uint16_t) newcap; 192 *(uint16_t*) capacity = (uint16_t) newcap;
193 } else if (width == 8) { 193 } else if (width == 8) {
194 *(uint8_t*) capacity = (uint8_t) newcap; 194 *(uint8_t*) capacity = (uint8_t) newcap;
223 223
224 // determine size and capacity 224 // determine size and capacity
225 size_t oldcap; 225 size_t oldcap;
226 size_t oldsize; 226 size_t oldsize;
227 size_t max_size; 227 size_t max_size;
228 if (width == 0 || width == CX_WORDSIZE) { 228 if (width == 0 || width == 8*sizeof(size_t)) {
229 oldcap = *(size_t*) capacity; 229 oldcap = *(size_t*) capacity;
230 oldsize = *(size_t*) size; 230 oldsize = *(size_t*) size;
231 max_size = SIZE_MAX; 231 max_size = SIZE_MAX;
232 } else if (width == 16) { 232 } else if (width == 16) {
233 oldcap = *(uint16_t*) capacity; 233 oldcap = *(uint16_t*) capacity;
301 // note: no overflow check here, b/c we cannot get here w/o allocation 301 // note: no overflow check here, b/c we cannot get here w/o allocation
302 memmove(start, src, elem_count * elem_size); 302 memmove(start, src, elem_count * elem_size);
303 303
304 // if any of size or capacity changed, store them back 304 // if any of size or capacity changed, store them back
305 if (newsize != oldsize || newcap != oldcap) { 305 if (newsize != oldsize || newcap != oldcap) {
306 if (width == 0 || width == CX_WORDSIZE) { 306 if (width == 0 || width == 8*sizeof(size_t)) {
307 *(size_t*) capacity = newcap; 307 *(size_t*) capacity = newcap;
308 *(size_t*) size = newsize; 308 *(size_t*) size = newsize;
309 } else if (width == 16) { 309 } else if (width == 16) {
310 *(uint16_t*) capacity = (uint16_t) newcap; 310 *(uint16_t*) capacity = (uint16_t) newcap;
311 *(uint16_t*) size = (uint16_t) newsize; 311 *(uint16_t*) size = (uint16_t) newsize;

mercurial