fx.collections: hashtable: fix handling of existing keys in put()

This commit is contained in:
2026-06-20 15:27:00 +01:00
parent c887a18a10
commit 5156971945
+16 -7
View File
@@ -282,18 +282,27 @@ static fx_status hashtable_put(
break;
} while (1);
fx_hashtable_item *item = fx_object_create(FX_TYPE_HASHTABLE_ITEM);
fx_hashtable_item *item = hashtable->t_items[index].i_item;
struct fx_hashtable_item_p *item_p = NULL;
if (!item) {
return FX_ERR_NO_MEMORY;
item = fx_object_create(FX_TYPE_HASHTABLE_ITEM);
if (!item) {
return FX_ERR_NO_MEMORY;
}
item_p = fx_object_get_private(item, FX_TYPE_HASHTABLE_ITEM);
fx_value_copy(&item_p->i_key, key);
hashtable->t_items[index].i_item = item;
hashtable->t_count++;
} else {
item_p = fx_object_get_private(item, FX_TYPE_HASHTABLE_ITEM);
fx_value_unset(&item_p->i_value);
}
struct fx_hashtable_item_p *item_p
= fx_object_get_private(item, FX_TYPE_HASHTABLE_ITEM);
fx_value_copy(&item_p->i_key, key);
fx_value_copy(&item_p->i_value, value);
hashtable->t_items[index].i_item = item;
hashtable->t_count++;
return FX_SUCCESS;
}