fx.collections: hashtable: fix handling of existing keys in put()
This commit is contained in:
@@ -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) {
|
||||
item = fx_object_create(FX_TYPE_HASHTABLE_ITEM);
|
||||
if (!item) {
|
||||
return FX_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
struct fx_hashtable_item_p *item_p
|
||||
= fx_object_get_private(item, FX_TYPE_HASHTABLE_ITEM);
|
||||
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++;
|
||||
} else {
|
||||
item_p = fx_object_get_private(item, FX_TYPE_HASHTABLE_ITEM);
|
||||
fx_value_unset(&item_p->i_value);
|
||||
}
|
||||
|
||||
fx_value_copy(&item_p->i_value, value);
|
||||
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user