improve cx_kv_list_insert() by using low level access to the list method default tip

Thu, 18 Sep 2025 00:40:27 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 18 Sep 2025 00:40:27 +0200
changeset 1379
9ad4a7011528
parent 1378
1b4fa55f7caa

improve cx_kv_list_insert() by using low level access to the list method

relates to #461

src/kv_list.c file | annotate | diff | comparison | revisions
--- a/src/kv_list.c	Thu Sep 18 00:36:42 2025 +0200
+++ b/src/kv_list.c	Thu Sep 18 00:40:27 2025 +0200
@@ -491,17 +491,11 @@
 int cx_kv_list_insert(CxList *list, size_t index, CxHashKey key, void *value) {
     cx_kv_list *kv_list = (cx_kv_list*)list;
 
-    // add the new node via emplacement (we don't want to look up the node again)
-    void *node_data = cxListEmplaceAt(list, index);
+    // insert the node
+    void *node_data = kv_list->list_methods->insert_element(&kv_list->list.base, index,
+        kv_list->list.base.collection.store_pointer ? &value : value);
     if (node_data == NULL) return -1; // LCOV_EXCL_LINE
 
-    // copy the data
-    if (list->collection.store_pointer) {
-        memcpy(node_data, &value, sizeof(void*));
-    } else {
-        memcpy(node_data, value, kv_list->list.base.collection.elem_size);
-    }
-
     // add the key to the map
     kv_list->map_methods->put(&kv_list->map->map_base.base, key, node_data);
     // TODO: get rid of the node again, when adding the entry to the map failed

mercurial