src/array_list.c

changeset 676
d0680a23d850
parent 670
4ad8ea3aee49
child 677
b09aae58bba4
equal deleted inserted replaced
675:765cf785b7fa 676:d0680a23d850
509 } 509 }
510 510
511 cx_array_list *list = cxCalloc(allocator, 1, sizeof(cx_array_list)); 511 cx_array_list *list = cxCalloc(allocator, 1, sizeof(cx_array_list));
512 if (list == NULL) return NULL; 512 if (list == NULL) return NULL;
513 513
514 list->base.cl = &cx_array_list_class;
515 list->base.allocator = allocator;
516 list->base.cmpfunc = comparator;
517 list->base.capacity = initial_capacity;
518
519 if (item_size > 0) {
520 list->base.itemsize = item_size;
521 } else {
522 item_size = sizeof(void*);
523 cxListStorePointers((CxList *) list);
524 }
525
526 // allocate the array after the real item_size is known
514 list->data = cxCalloc(allocator, initial_capacity, item_size); 527 list->data = cxCalloc(allocator, initial_capacity, item_size);
515 if (list->data == NULL) { 528 if (list->data == NULL) {
516 cxFree(allocator, list); 529 cxFree(allocator, list);
517 return NULL; 530 return NULL;
518 } 531 }
519 532
520 list->base.cl = &cx_array_list_class;
521 list->base.allocator = allocator;
522 list->base.cmpfunc = comparator;
523 list->base.capacity = initial_capacity;
524
525 if (item_size > 0) {
526 list->base.itemsize = item_size;
527 } else {
528 cxListStorePointers((CxList *) list);
529 }
530
531 // configure the reallocator 533 // configure the reallocator
532 list->reallocator.realloc = cx_arl_realloc; 534 list->reallocator.realloc = cx_arl_realloc;
533 list->reallocator.ptr1 = (void *) allocator; 535 list->reallocator.ptr1 = (void *) allocator;
534 536
535 return (CxList *) list; 537 return (CxList *) list;

mercurial