src/array_list.c

changeset 1018
c773da859bad
parent 999
84fc42b04d3b
child 1019
09c6fe8fe3b9
equal deleted inserted replaced
1017:b0098854071f 1018:c773da859bad
106 106
107 // determine size and capacity 107 // determine size and capacity
108 size_t oldcap; 108 size_t oldcap;
109 size_t oldsize; 109 size_t oldsize;
110 size_t max_size; 110 size_t max_size;
111 if (width == 0 || width == __WORDSIZE) { 111 if (width == 0 || width == CX_WORDSIZE) {
112 oldcap = *(size_t*) capacity; 112 oldcap = *(size_t*) capacity;
113 oldsize = *(size_t*) size; 113 oldsize = *(size_t*) size;
114 max_size = SIZE_MAX; 114 max_size = SIZE_MAX;
115 } else if (width == 16) { 115 } else if (width == 16) {
116 oldcap = *(uint16_t*) capacity; 116 oldcap = *(uint16_t*) capacity;
119 } else if (width == 8) { 119 } else if (width == 8) {
120 oldcap = *(uint8_t*) capacity; 120 oldcap = *(uint8_t*) capacity;
121 oldsize = *(uint8_t*) size; 121 oldsize = *(uint8_t*) size;
122 max_size = UINT8_MAX; 122 max_size = UINT8_MAX;
123 } 123 }
124 #if __WORDSIZE == 64 124 #if CX_WORDSIZE == 64
125 else if (width == 32) { 125 else if (width == 32) {
126 oldcap = *(uint32_t*) capacity; 126 oldcap = *(uint32_t*) capacity;
127 oldsize = *(uint32_t*) size; 127 oldsize = *(uint32_t*) size;
128 max_size = UINT32_MAX; 128 max_size = UINT32_MAX;
129 } 129 }
160 160
161 // store new pointer 161 // store new pointer
162 *array = newmem; 162 *array = newmem;
163 163
164 // store new capacity 164 // store new capacity
165 if (width == 0 || width == __WORDSIZE) { 165 if (width == 0 || width == CX_WORDSIZE) {
166 *(size_t*) capacity = newcap; 166 *(size_t*) capacity = newcap;
167 } else if (width == 16) { 167 } else if (width == 16) {
168 *(uint16_t*) capacity = newcap; 168 *(uint16_t*) capacity = newcap;
169 } else if (width == 8) { 169 } else if (width == 8) {
170 *(uint8_t*) capacity = newcap; 170 *(uint8_t*) capacity = newcap;
171 } 171 }
172 #if __WORDSIZE == 64 172 #if CX_WORDSIZE == 64
173 else if (width == 32) { 173 else if (width == 32) {
174 *(uint32_t*) capacity = newcap; 174 *(uint32_t*) capacity = newcap;
175 } 175 }
176 #endif 176 #endif
177 } 177 }
199 199
200 // determine size and capacity 200 // determine size and capacity
201 size_t oldcap; 201 size_t oldcap;
202 size_t oldsize; 202 size_t oldsize;
203 size_t max_size; 203 size_t max_size;
204 if (width == 0 || width == __WORDSIZE) { 204 if (width == 0 || width == CX_WORDSIZE) {
205 oldcap = *(size_t*) capacity; 205 oldcap = *(size_t*) capacity;
206 oldsize = *(size_t*) size; 206 oldsize = *(size_t*) size;
207 max_size = SIZE_MAX; 207 max_size = SIZE_MAX;
208 } else if (width == 16) { 208 } else if (width == 16) {
209 oldcap = *(uint16_t*) capacity; 209 oldcap = *(uint16_t*) capacity;
212 } else if (width == 8) { 212 } else if (width == 8) {
213 oldcap = *(uint8_t*) capacity; 213 oldcap = *(uint8_t*) capacity;
214 oldsize = *(uint8_t*) size; 214 oldsize = *(uint8_t*) size;
215 max_size = UINT8_MAX; 215 max_size = UINT8_MAX;
216 } 216 }
217 #if __WORDSIZE == 64 217 #if CX_WORDSIZE == 64
218 else if (width == 32) { 218 else if (width == 32) {
219 oldcap = *(uint32_t*) capacity; 219 oldcap = *(uint32_t*) capacity;
220 oldsize = *(uint32_t*) size; 220 oldsize = *(uint32_t*) size;
221 max_size = UINT32_MAX; 221 max_size = UINT32_MAX;
222 } 222 }
276 // copy elements and set new size 276 // copy elements and set new size
277 memmove(start, src, elem_count * elem_size); 277 memmove(start, src, elem_count * elem_size);
278 278
279 // if any of size or capacity changed, store them back 279 // if any of size or capacity changed, store them back
280 if (newsize != oldsize || newcap != oldcap) { 280 if (newsize != oldsize || newcap != oldcap) {
281 if (width == 0 || width == __WORDSIZE) { 281 if (width == 0 || width == CX_WORDSIZE) {
282 *(size_t*) capacity = newcap; 282 *(size_t*) capacity = newcap;
283 *(size_t*) size = newsize; 283 *(size_t*) size = newsize;
284 } else if (width == 16) { 284 } else if (width == 16) {
285 *(uint16_t*) capacity = newcap; 285 *(uint16_t*) capacity = newcap;
286 *(uint16_t*) size = newsize; 286 *(uint16_t*) size = newsize;
287 } else if (width == 8) { 287 } else if (width == 8) {
288 *(uint8_t*) capacity = newcap; 288 *(uint8_t*) capacity = newcap;
289 *(uint8_t*) size = newsize; 289 *(uint8_t*) size = newsize;
290 } 290 }
291 #if __WORDSIZE == 64 291 #if CX_WORDSIZE == 64
292 else if (width == 32) { 292 else if (width == 32) {
293 *(uint32_t*) capacity = newcap; 293 *(uint32_t*) capacity = newcap;
294 *(uint32_t*) size = newsize; 294 *(uint32_t*) size = newsize;
295 } 295 }
296 #endif 296 #endif

mercurial