| 1011 allocator = cxDefaultAllocator; |
1011 allocator = cxDefaultAllocator; |
| 1012 } |
1012 } |
| 1013 |
1013 |
| 1014 cx_array_list *list = cxCalloc(allocator, 1, sizeof(cx_array_list)); |
1014 cx_array_list *list = cxCalloc(allocator, 1, sizeof(cx_array_list)); |
| 1015 if (list == NULL) return NULL; |
1015 if (list == NULL) return NULL; |
| 1016 |
1016 cx_list_init((CxList*)list, &cx_array_list_class, |
| 1017 list->base.cl = &cx_array_list_class; |
1017 allocator, comparator, elem_size); |
| 1018 list->base.collection.allocator = allocator; |
|
| 1019 list->capacity = initial_capacity; |
1018 list->capacity = initial_capacity; |
| 1020 |
1019 |
| 1021 if (elem_size > 0) { |
|
| 1022 list->base.collection.elem_size = elem_size; |
|
| 1023 list->base.collection.cmpfunc = comparator; |
|
| 1024 } else { |
|
| 1025 elem_size = sizeof(void *); |
|
| 1026 list->base.collection.cmpfunc = comparator == NULL ? cx_cmp_ptr : comparator; |
|
| 1027 cxListStorePointers((CxList *) list); |
|
| 1028 } |
|
| 1029 |
|
| 1030 // allocate the array after the real elem_size is known |
1020 // allocate the array after the real elem_size is known |
| 1031 list->data = cxCalloc(allocator, initial_capacity, elem_size); |
1021 list->data = cxCalloc(allocator, initial_capacity, |
| |
1022 list->base.collection.elem_size); |
| 1032 if (list->data == NULL) { // LCOV_EXCL_START |
1023 if (list->data == NULL) { // LCOV_EXCL_START |
| 1033 cxFree(allocator, list); |
1024 cxFree(allocator, list); |
| 1034 return NULL; |
1025 return NULL; |
| 1035 } // LCOV_EXCL_STOP |
1026 } // LCOV_EXCL_STOP |
| 1036 |
1027 |