src/kv_list.c

changeset 1352
8428516137dd
parent 1350
189756516eaa
child 1353
5a13b9c1c57b
--- 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));
     

mercurial