add CX_DISABLE_ARRAY_LIST_SWAP_SBO flag

Sat, 13 Jan 2024 17:51:42 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 13 Jan 2024 17:51:42 +0100
changeset 804
5136f2fc32ec
parent 803
0711d869ce4d
child 805
26500fc24058

add CX_DISABLE_ARRAY_LIST_SWAP_SBO flag

src/array_list.c file | annotate | diff | comparison | revisions
src/cx/array_list.h file | annotate | diff | comparison | revisions
tests/test_list.c file | annotate | diff | comparison | revisions
     1.1 --- a/src/array_list.c	Fri Jan 12 20:24:29 2024 +0100
     1.2 +++ b/src/array_list.c	Sat Jan 13 17:51:42 2024 +0100
     1.3 @@ -107,6 +107,8 @@
     1.4  #define CX_ARRAY_SWAP_SBO_SIZE 128
     1.5  #endif
     1.6  
     1.7 +bool CX_DISABLE_ARRAY_LIST_SWAP_SBO = false;
     1.8 +
     1.9  void cx_array_swap(
    1.10          void *arr,
    1.11          size_t elem_size,
    1.12 @@ -122,7 +124,7 @@
    1.13      void *tmp;
    1.14  
    1.15      // decide if we can use the local buffer
    1.16 -    if (elem_size > CX_ARRAY_SWAP_SBO_SIZE) {
    1.17 +    if (elem_size > CX_ARRAY_SWAP_SBO_SIZE || CX_DISABLE_ARRAY_LIST_SWAP_SBO) {
    1.18          tmp = malloc(elem_size);
    1.19          // we don't want to enforce error handling
    1.20          if (tmp == NULL) abort();
     2.1 --- a/src/cx/array_list.h	Fri Jan 12 20:24:29 2024 +0100
     2.2 +++ b/src/cx/array_list.h	Sat Jan 13 17:51:42 2024 +0100
     2.3 @@ -45,6 +45,12 @@
     2.4  #endif
     2.5  
     2.6  /**
     2.7 + * Set this flag to true, if you want to disable the use of SBO for
     2.8 + * array list swap operations.
     2.9 + */
    2.10 +extern bool CX_DISABLE_ARRAY_LIST_SWAP_SBO;
    2.11 +
    2.12 +/**
    2.13   * Defines a reallocation mechanism for arrays.
    2.14   */
    2.15  struct cx_array_reallocator_s {
     3.1 --- a/tests/test_list.c	Fri Jan 12 20:24:29 2024 +0100
     3.2 +++ b/tests/test_list.c	Sat Jan 13 17:51:42 2024 +0100
     3.3 @@ -1086,8 +1086,9 @@
     3.4          CX_TEST_CALL_SUBROUTINE(test_list_verify_swap, list, isptrlist, true);
     3.5          CX_DISABLE_LINKED_LIST_SWAP_SBO = false;
     3.6      } else {
     3.7 -        // TODO: currently, SBO for swap operation cannot be disabled for array lists
     3.8 -        CX_TEST_ASSERT(true);
     3.9 +        CX_DISABLE_ARRAY_LIST_SWAP_SBO = true;
    3.10 +        CX_TEST_CALL_SUBROUTINE(test_list_verify_swap, list, isptrlist, false);
    3.11 +        CX_DISABLE_ARRAY_LIST_SWAP_SBO = false;
    3.12      }
    3.13  })
    3.14  

mercurial