From a233700a21b3fcca558ee0728aabdd18f2ac8017 Mon Sep 17 00:00:00 2001 From: Michal Vasko Date: Tue, 31 Mar 2020 15:50:40 +0200 Subject: [PATCH] dict BUGFIX use special function for resizing Fixes #1045 --- src/hash_table.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/hash_table.c b/src/hash_table.c index 92c10225af..59c1c4c4bf 100644 --- a/src/hash_table.c +++ b/src/hash_table.c @@ -191,6 +191,29 @@ lydict_remove(struct ly_ctx *ctx, const char *value) pthread_mutex_unlock(&ctx->dict.lock); } +static int +lydict_resize_val_eq(void *val1_p, void *val2_p, int UNUSED(mod), void *UNUSED(cb_data)) +{ + if (!val1_p || !val2_p) { + LOGARG; + return 0; + } + + const char *str1 = ((struct dict_rec *)val1_p)->value; + const char *str2 = ((struct dict_rec *)val2_p)->value; + + if (!str1 || !str2) { + LOGARG; + return 0; + } + + if (strcmp(str1, str2) == 0) { + return 1; + } + + return 0; +} + static char * dict_insert(struct ly_ctx *ctx, char *value, size_t len, int zerocopy) { @@ -206,7 +229,7 @@ dict_insert(struct ly_ctx *ctx, char *value, size_t len, int zerocopy) rec.refcount = 1; LOGDBG(LY_LDGDICT, "inserting \"%s\"", rec.value); - ret = lyht_insert(ctx->dict.hash_tab, (void *)&rec, hash, (void **)&match); + ret = lyht_insert_with_resize_cb(ctx->dict.hash_tab, (void *)&rec, hash, lydict_resize_val_eq, (void **)&match); if (ret == 1) { match->refcount++; if (zerocopy) {