Mon, 15 Jan 2024 20:59:18 +0100
remove flags to disable SBO in tests - fix #343 fix #358
docs/src/install.md | file | annotate | diff | comparison | revisions | |
src/array_list.c | file | annotate | diff | comparison | revisions | |
src/cx/array_list.h | file | annotate | diff | comparison | revisions | |
src/cx/linked_list.h | file | annotate | diff | comparison | revisions | |
src/linked_list.c | file | annotate | diff | comparison | revisions | |
tests/test_list.c | file | annotate | diff | comparison | revisions |
1.1 --- a/docs/src/install.md Sun Jan 14 13:50:17 2024 +0100 1.2 +++ b/docs/src/install.md Mon Jan 15 20:59:18 2024 +0100 1.3 @@ -26,10 +26,10 @@ 1.4 --------------------------------- --------------------------------------------------------------------- ---------- 1.5 CX_ARRAY_SWAP_SBO_SIZE The maximum item size in an array list that uses SBO. 128 1.6 1.7 +CX_LINKED_LIST_SWAP_SBO_SIZE The maximum item size that uses SBO swap instead of relinking. 128 1.8 + 1.9 CX_LINKED_LIST_SORT_SBO_SIZE The maximum list size that uses SBO during sort. 1024 1.10 1.11 -CX_LINKED_LIST_SWAP_SBO_SIZE The maximum item size that uses SBO swap instead of relinking. 128 1.12 - 1.13 CX_PRINTF_SBO_SIZE The maximum string length printf.h uses stack memory for. 512 1.14 1.15 CX_STRSTR_SBO_SIZE The maximum length of the "needle" in cx_strstr that can use SBO. 512
2.1 --- a/src/array_list.c Sun Jan 14 13:50:17 2024 +0100 2.2 +++ b/src/array_list.c Mon Jan 15 20:59:18 2024 +0100 2.3 @@ -106,8 +106,7 @@ 2.4 #ifndef CX_ARRAY_SWAP_SBO_SIZE 2.5 #define CX_ARRAY_SWAP_SBO_SIZE 128 2.6 #endif 2.7 - 2.8 -bool CX_DISABLE_ARRAY_LIST_SWAP_SBO = false; 2.9 +unsigned cx_array_swap_sbo_size = CX_ARRAY_SWAP_SBO_SIZE; 2.10 2.11 void cx_array_swap( 2.12 void *arr, 2.13 @@ -124,7 +123,7 @@ 2.14 void *tmp; 2.15 2.16 // decide if we can use the local buffer 2.17 - if (elem_size > CX_ARRAY_SWAP_SBO_SIZE || CX_DISABLE_ARRAY_LIST_SWAP_SBO) { 2.18 + if (elem_size > CX_ARRAY_SWAP_SBO_SIZE) { 2.19 tmp = malloc(elem_size); 2.20 // we don't want to enforce error handling 2.21 if (tmp == NULL) abort();
3.1 --- a/src/cx/array_list.h Sun Jan 14 13:50:17 2024 +0100 3.2 +++ b/src/cx/array_list.h Mon Jan 15 20:59:18 2024 +0100 3.3 @@ -45,10 +45,9 @@ 3.4 #endif 3.5 3.6 /** 3.7 - * Set this flag to true, if you want to disable the use of SBO for 3.8 - * array list swap operations. 3.9 + * The maximum item size in an array list that fits into stack buffer when swapped. 3.10 */ 3.11 -extern bool CX_DISABLE_ARRAY_LIST_SWAP_SBO; 3.12 +extern unsigned cx_array_swap_sbo_size; 3.13 3.14 /** 3.15 * Defines a reallocation mechanism for arrays.
4.1 --- a/src/cx/linked_list.h Sun Jan 14 13:50:17 2024 +0100 4.2 +++ b/src/cx/linked_list.h Mon Jan 15 20:59:18 2024 +0100 4.3 @@ -45,10 +45,9 @@ 4.4 #endif 4.5 4.6 /** 4.7 - * Set this flag to true, if you want to disable the use of SBO for 4.8 - * linked list swap operations. 4.9 + * The maximum item size that uses SBO swap instead of relinking. 4.10 */ 4.11 -extern bool CX_DISABLE_LINKED_LIST_SWAP_SBO; 4.12 +extern unsigned cx_linked_list_swap_sbo_size; 4.13 4.14 /** 4.15 * Allocates a linked list for storing elements with \p item_size bytes each.
5.1 --- a/src/linked_list.c Sun Jan 14 13:50:17 2024 +0100 5.2 +++ b/src/linked_list.c Mon Jan 15 20:59:18 2024 +0100 5.3 @@ -480,8 +480,6 @@ 5.4 5.5 // HIGH LEVEL LINKED LIST IMPLEMENTATION 5.6 5.7 -bool CX_DISABLE_LINKED_LIST_SWAP_SBO = false; 5.8 - 5.9 typedef struct cx_linked_list_node cx_linked_list_node; 5.10 struct cx_linked_list_node { 5.11 cx_linked_list_node *prev; 5.12 @@ -629,6 +627,7 @@ 5.13 #ifndef CX_LINKED_LIST_SWAP_SBO_SIZE 5.14 #define CX_LINKED_LIST_SWAP_SBO_SIZE 128 5.15 #endif 5.16 +unsigned cx_linked_list_swap_sbo_size = CX_LINKED_LIST_SWAP_SBO_SIZE; 5.17 5.18 static int cx_ll_swap( 5.19 struct cx_list_s *list, 5.20 @@ -653,6 +652,7 @@ 5.21 if (left < mid && right < mid) { 5.22 // case 1: both items left from mid 5.23 nleft = cx_ll_node_at(ll, left); 5.24 + assert(nleft != NULL); 5.25 nright = nleft; 5.26 for (size_t c = left; c < right; c++) { 5.27 nright = nright->next; 5.28 @@ -660,6 +660,7 @@ 5.29 } else if (left >= mid && right >= mid) { 5.30 // case 2: both items right from mid 5.31 nright = cx_ll_node_at(ll, right); 5.32 + assert(nright != NULL); 5.33 nleft = nright; 5.34 for (size_t c = right; c > left; c--) { 5.35 nleft = nleft->prev; 5.36 @@ -706,7 +707,7 @@ 5.37 } 5.38 } 5.39 5.40 - if (list->item_size > CX_LINKED_LIST_SWAP_SBO_SIZE || CX_DISABLE_LINKED_LIST_SWAP_SBO) { 5.41 + if (list->item_size > CX_LINKED_LIST_SWAP_SBO_SIZE) { 5.42 cx_linked_list_node *prev = nleft->prev; 5.43 cx_linked_list_node *next = nright->next; 5.44 cx_linked_list_node *midstart = nleft->next;
6.1 --- a/tests/test_list.c Sun Jan 14 13:50:17 2024 +0100 6.2 +++ b/tests/test_list.c Mon Jan 15 20:59:18 2024 +0100 6.3 @@ -867,30 +867,29 @@ 6.4 cx_testing_allocator_destroy(&talloc); 6.5 #define roll_out_test_combos(name, body) \ 6.6 static CX_TEST_SUBROUTINE(test_list_verify_##name, CxList *list, \ 6.7 - __attribute__((__unused__)) bool isptrlist, \ 6.8 - __attribute__((__unused__)) bool islinkedlist) body \ 6.9 + __attribute__((__unused__)) bool isptrlist) body \ 6.10 CX_TEST(test_list_ll_##name) { \ 6.11 set_up_combo \ 6.12 CxList *list = cxLinkedListCreate(alloc, cx_cmp_int, sizeof(int)); \ 6.13 - CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false, true); \ 6.14 + CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false); \ 6.15 tear_down_combo \ 6.16 } \ 6.17 CX_TEST(test_list_arl_##name) { \ 6.18 set_up_combo \ 6.19 CxList *list = cxArrayListCreate(alloc, cx_cmp_int, sizeof(int), 8); \ 6.20 - CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false, false); \ 6.21 + CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, false); \ 6.22 tear_down_combo \ 6.23 } \ 6.24 CX_TEST(test_list_pll_##name) { \ 6.25 set_up_combo \ 6.26 CxList *list = cxLinkedListCreate(alloc, cx_cmp_int, CX_STORE_POINTERS); \ 6.27 - CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true, true); \ 6.28 + CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true); \ 6.29 tear_down_combo \ 6.30 } \ 6.31 CX_TEST(test_list_parl_##name) { \ 6.32 set_up_combo \ 6.33 CxList *list = cxArrayListCreate(alloc, cx_cmp_int, CX_STORE_POINTERS, 8); \ 6.34 - CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true, false); \ 6.35 + CX_TEST_CALL_SUBROUTINE(test_list_verify_##name, list, true); \ 6.36 tear_down_combo \ 6.37 } 6.38 #define array_init(...) {__VA_ARGS__} 6.39 @@ -1080,17 +1079,18 @@ 6.40 } 6.41 }) 6.42 6.43 -roll_out_test_combos(swap_no_sbo, { 6.44 - if (islinkedlist) { 6.45 - CX_DISABLE_LINKED_LIST_SWAP_SBO = true; 6.46 - CX_TEST_CALL_SUBROUTINE(test_list_verify_swap, list, isptrlist, true); 6.47 - CX_DISABLE_LINKED_LIST_SWAP_SBO = false; 6.48 - } else { 6.49 - CX_DISABLE_ARRAY_LIST_SWAP_SBO = true; 6.50 - CX_TEST_CALL_SUBROUTINE(test_list_verify_swap, list, isptrlist, false); 6.51 - CX_DISABLE_ARRAY_LIST_SWAP_SBO = false; 6.52 - } 6.53 -}) 6.54 +CX_TEST(test_list_ll_swap_no_sbo) { 6.55 + set_up_combo 6.56 + CxList *list = cxLinkedListCreate(alloc, cx_cmp_int, 2*cx_linked_list_swap_sbo_size); 6.57 + CX_TEST_CALL_SUBROUTINE(test_list_verify_swap, list, false); 6.58 + tear_down_combo 6.59 +} 6.60 +CX_TEST(test_list_arl_swap_no_sbo) { 6.61 + set_up_combo 6.62 + CxList *list = cxArrayListCreate(alloc, cx_cmp_int, 2*cx_array_swap_sbo_size, 8); 6.63 + CX_TEST_CALL_SUBROUTINE(test_list_verify_swap, list, false); 6.64 + tear_down_combo 6.65 +} 6.66 6.67 roll_out_test_combos(find, { 6.68 const size_t testdata_len = 500; 6.69 @@ -1368,7 +1368,6 @@ 6.70 cx_test_register(suite, test_list_arl_swap); 6.71 cx_test_register(suite, test_list_parl_swap); 6.72 cx_test_register(suite, test_list_arl_swap_no_sbo); 6.73 - cx_test_register(suite, test_list_parl_swap_no_sbo); 6.74 cx_test_register(suite, test_list_arl_find); 6.75 cx_test_register(suite, test_list_parl_find); 6.76 cx_test_register(suite, test_list_arl_sort); 6.77 @@ -1440,7 +1439,6 @@ 6.78 cx_test_register(suite, test_list_ll_swap); 6.79 cx_test_register(suite, test_list_pll_swap); 6.80 cx_test_register(suite, test_list_ll_swap_no_sbo); 6.81 - cx_test_register(suite, test_list_pll_swap_no_sbo); 6.82 cx_test_register(suite, test_list_ll_find); 6.83 cx_test_register(suite, test_list_pll_find); 6.84 cx_test_register(suite, test_list_ll_sort);