src/list.c

changeset 677
b09aae58bba4
parent 666
b5dd654deb3b
child 680
19379743e5a0
     1.1 --- a/src/list.c	Fri Apr 07 11:30:28 2023 +0200
     1.2 +++ b/src/list.c	Sun Apr 09 19:03:58 2023 +0200
     1.3 @@ -32,7 +32,7 @@
     1.4  
     1.5  // <editor-fold desc="Store Pointers Functionality">
     1.6  
     1.7 -static _Thread_local CxListComparator cx_pl_cmpfunc_impl;
     1.8 +static _Thread_local cx_compare_func cx_pl_cmpfunc_impl;
     1.9  
    1.10  static int cx_pl_cmpfunc(
    1.11          void const *l,
    1.12 @@ -179,6 +179,7 @@
    1.13  };
    1.14  
    1.15  void cxListStoreObjects(CxList *list) {
    1.16 +    list->store_pointer = false;
    1.17      if (list->climpl != NULL) {
    1.18          list->cl = list->climpl;
    1.19          list->climpl = NULL;
    1.20 @@ -186,75 +187,28 @@
    1.21  }
    1.22  
    1.23  void cxListStorePointers(CxList *list) {
    1.24 -    list->itemsize = sizeof(void *);
    1.25 +    list->item_size = sizeof(void *);
    1.26 +    list->store_pointer = true;
    1.27      list->climpl = list->cl;
    1.28      list->cl = &cx_pointer_list_class;
    1.29  }
    1.30  
    1.31 -bool cxListIsStoringPointers(CxList const *list) {
    1.32 -    return list->climpl != NULL;
    1.33 -}
    1.34 -
    1.35  // </editor-fold>
    1.36  
    1.37 -void cx_list_invoke_destructor(
    1.38 -        CxList const *list,
    1.39 -        void *elem
    1.40 -) {
    1.41 -    switch (list->content_destructor_type) {
    1.42 -        case CX_DESTRUCTOR_SIMPLE: {
    1.43 -            cx_list_invoke_simple_destructor(list, elem);
    1.44 -            break;
    1.45 +void cxListDestroy(CxList *list) {
    1.46 +    if (list->simple_destructor) {
    1.47 +        CxIterator iter = cxListIterator(list);
    1.48 +        cx_foreach(void*, elem, iter) {
    1.49 +            // already correctly resolved pointer - immediately invoke dtor
    1.50 +            list->simple_destructor(elem);
    1.51          }
    1.52 -        case CX_DESTRUCTOR_ADVANCED: {
    1.53 -            cx_list_invoke_advanced_destructor(list, elem);
    1.54 -            break;
    1.55 +    }
    1.56 +    if (list->advanced_destructor) {
    1.57 +        CxIterator iter = cxListIterator(list);
    1.58 +        cx_foreach(void*, elem, iter) {
    1.59 +            // already correctly resolved pointer - immediately invoke dtor
    1.60 +            list->advanced_destructor(list->destructor_data, elem);
    1.61          }
    1.62 -        case CX_DESTRUCTOR_NONE:
    1.63 -            break; // nothing
    1.64 -    }
    1.65 -}
    1.66 -
    1.67 -void cx_list_invoke_simple_destructor(
    1.68 -        CxList const *list,
    1.69 -        void *elem
    1.70 -) {
    1.71 -    if (cxListIsStoringPointers(list)) {
    1.72 -        elem = *((void **) elem);
    1.73 -    }
    1.74 -    list->simple_destructor(elem);
    1.75 -}
    1.76 -
    1.77 -void cx_list_invoke_advanced_destructor(
    1.78 -        CxList const *list,
    1.79 -        void *elem
    1.80 -) {
    1.81 -    if (cxListIsStoringPointers(list)) {
    1.82 -        elem = *((void **) elem);
    1.83 -    }
    1.84 -    list->advanced_destructor.func(list->advanced_destructor.data, elem);
    1.85 -}
    1.86 -
    1.87 -void cxListDestroy(CxList *list) {
    1.88 -    switch (list->content_destructor_type) {
    1.89 -        case CX_DESTRUCTOR_SIMPLE: {
    1.90 -            CxIterator iter = cxListIterator(list);
    1.91 -            cx_foreach(void*, elem, iter) {
    1.92 -                // already correctly resolved pointer - immediately invoke dtor
    1.93 -                list->simple_destructor(elem);
    1.94 -            }
    1.95 -            break;
    1.96 -        }
    1.97 -        case CX_DESTRUCTOR_ADVANCED: {
    1.98 -            CxIterator iter = cxListIterator(list);
    1.99 -            cx_foreach(void*, elem, iter) {
   1.100 -                // already correctly resolved pointer - immediately invoke dtor
   1.101 -                list->advanced_destructor.func(list->advanced_destructor.data, elem);
   1.102 -            }
   1.103 -            break;
   1.104 -        }
   1.105 -        case CX_DESTRUCTOR_NONE:
   1.106 -            break; // nothing
   1.107      }
   1.108  
   1.109      list->cl->destructor(list);

mercurial