Sat, 13 Jan 2024 17:51:42 +0100
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 |
--- a/src/array_list.c Fri Jan 12 20:24:29 2024 +0100 +++ b/src/array_list.c Sat Jan 13 17:51:42 2024 +0100 @@ -107,6 +107,8 @@ #define CX_ARRAY_SWAP_SBO_SIZE 128 #endif +bool CX_DISABLE_ARRAY_LIST_SWAP_SBO = false; + void cx_array_swap( void *arr, size_t elem_size, @@ -122,7 +124,7 @@ void *tmp; // decide if we can use the local buffer - if (elem_size > CX_ARRAY_SWAP_SBO_SIZE) { + if (elem_size > CX_ARRAY_SWAP_SBO_SIZE || CX_DISABLE_ARRAY_LIST_SWAP_SBO) { tmp = malloc(elem_size); // we don't want to enforce error handling if (tmp == NULL) abort();
--- a/src/cx/array_list.h Fri Jan 12 20:24:29 2024 +0100 +++ b/src/cx/array_list.h Sat Jan 13 17:51:42 2024 +0100 @@ -45,6 +45,12 @@ #endif /** + * Set this flag to true, if you want to disable the use of SBO for + * array list swap operations. + */ +extern bool CX_DISABLE_ARRAY_LIST_SWAP_SBO; + +/** * Defines a reallocation mechanism for arrays. */ struct cx_array_reallocator_s {
--- a/tests/test_list.c Fri Jan 12 20:24:29 2024 +0100 +++ b/tests/test_list.c Sat Jan 13 17:51:42 2024 +0100 @@ -1086,8 +1086,9 @@ CX_TEST_CALL_SUBROUTINE(test_list_verify_swap, list, isptrlist, true); CX_DISABLE_LINKED_LIST_SWAP_SBO = false; } else { - // TODO: currently, SBO for swap operation cannot be disabled for array lists - CX_TEST_ASSERT(true); + CX_DISABLE_ARRAY_LIST_SWAP_SBO = true; + CX_TEST_CALL_SUBROUTINE(test_list_verify_swap, list, isptrlist, false); + CX_DISABLE_ARRAY_LIST_SWAP_SBO = false; } })