Skip to content

Commit

Permalink
dict BUGFIX use special function for resizing
Browse files Browse the repository at this point in the history
Fixes #1045
  • Loading branch information
michalvasko committed Mar 31, 2020
1 parent 46b1edd commit 2edd550
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/hash_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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) {
Expand Down

0 comments on commit 2edd550

Please sign in to comment.