tree data OPTIMIZE duplication of a hash table
Allocate the exact amount of memory for a new hash table as was
allocated for the old one at once.
diff --git a/src/tree_data.c b/src/tree_data.c
index e1463ea..5bddf5f 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -2148,6 +2148,11 @@
struct lyd_node *child;
if (options & LYD_DUP_RECURSIVE) {
+ /* create a hash table with the size of the previous hash table (duplicate) */
+ if (orig->children_ht) {
+ ((struct lyd_node_inner *)dup)->children_ht = lyht_new(orig->children_ht->size, sizeof(struct lyd_node *), lyd_hash_table_val_equal, NULL, 1);
+ }
+
/* duplicate all the children */
LY_LIST_FOR(orig->child, child) {
LY_CHECK_GOTO(ret = lyd_dup_r(child, trg_ctx, dup, LYD_INSERT_NODE_LAST, NULL, options, NULL), error);