src/linked_list.c

changeset 661
0a71ac9547fd
parent 655
7340c4255f1f
child 662
d0d95740071b
equal deleted inserted replaced
660:4738a9065907 661:0a71ac9547fd
277 size++; 277 size++;
278 } 278 }
279 return size; 279 return size;
280 } 280 }
281 281
282 #ifndef CX_LINKED_LIST_SORT_SBO_SIZE
283 #define CX_LINKED_LIST_SORT_SBO_SIZE 1024
284 #endif
285
282 static void *cx_linked_list_sort_merge( 286 static void *cx_linked_list_sort_merge(
283 ptrdiff_t loc_prev, 287 ptrdiff_t loc_prev,
284 ptrdiff_t loc_next, 288 ptrdiff_t loc_next,
285 ptrdiff_t loc_data, 289 ptrdiff_t loc_data,
286 size_t length, 290 size_t length,
287 void *ls, 291 void *ls,
288 void *le, 292 void *le,
289 void *re, 293 void *re,
290 CxListComparator cmp_func 294 CxListComparator cmp_func
291 ) { 295 ) {
292 const size_t sbo_len = 1024; 296 void *sbo[CX_LINKED_LIST_SORT_SBO_SIZE];
293 void *sbo[sbo_len]; 297 void **sorted = length >= CX_LINKED_LIST_SORT_SBO_SIZE ?
294 void **sorted = (length >= sbo_len) ? malloc(sizeof(void *) * length) : sbo; 298 malloc(sizeof(void *) * length) : sbo;
295 if (sorted == NULL) abort(); 299 if (sorted == NULL) abort();
296 void *rc, *lc; 300 void *rc, *lc;
297 301
298 lc = ls; 302 lc = ls;
299 rc = le; 303 rc = le;

mercurial