# HG changeset patch # User Mike Becker # Date 1756329233 -7200 # Node ID 8428516137dd9e75b43ba42ba52e0188ba0f4ad3 # Parent 4407229bd944ad8b928761d80c021c42b5f01dc1 make comparisons between kv_list and linked_list optimizable relates to #461 diff -r 4407229bd944 -r 8428516137dd src/kv_list.c --- a/src/kv_list.c Wed Aug 27 23:07:39 2025 +0200 +++ b/src/kv_list.c Wed Aug 27 23:13:53 2025 +0200 @@ -153,15 +153,6 @@ kv_list->list_methods->sort(list); } -static int cx_kvl_compare( - const struct cx_list_s *list, - const struct cx_list_s *other -) { - // TODO: make it so that comparison with normal linked lists is also optimized - const cx_kv_list *kv_list = (const cx_kv_list*)list; - return kv_list->list_methods->compare(list, other); -} - static void cx_kvl_reverse(struct cx_list_s *list) { cx_kv_list *kv_list = (cx_kv_list*)list; kv_list->list_methods->reverse(list); @@ -189,7 +180,7 @@ cx_kvl_at, cx_kvl_find_remove, cx_kvl_sort, - cx_kvl_compare, + NULL, cx_kvl_reverse, cx_kvl_iterator, }; @@ -212,6 +203,10 @@ return NULL; } // LCOV_EXCL_STOP + // patch the kv-list class with the compare function of the linked list + // this allows cxListCompare() to optimize comparisons between linked lists and kv-list + cx_kv_list_class.compare = list->cl->compare; + // reallocate the map to add memory for the list back-reference struct cx_kv_list_map_s *kv_map = cxRealloc(allocator, map, sizeof(struct cx_kv_list_map_s));