mirror of
https://github.com/json-c/json-c.git
synced 2026-04-02 20:09:06 +08:00
reduce duplicate hash computation in json_object_object_add()
This can be a very considerable performance saver.
This commit is contained in:
@@ -403,10 +403,11 @@ void json_object_object_add(struct json_object* jso, const char *key,
|
||||
// and re-adding it, so the existing key remains valid.
|
||||
json_object *existing_value = NULL;
|
||||
struct lh_entry *existing_entry;
|
||||
existing_entry = lh_table_lookup_entry(jso->o.c_object, (void*)key);
|
||||
const unsigned long hash = lh_get_hash(jso->o.c_object, (void*)key);
|
||||
existing_entry = lh_table_lookup_entry_w_hash(jso->o.c_object, (void*)key, hash);
|
||||
if (!existing_entry)
|
||||
{
|
||||
lh_table_insert(jso->o.c_object, strdup(key), val);
|
||||
lh_table_insert_w_hash(jso->o.c_object, strdup(key), val, hash);
|
||||
return;
|
||||
}
|
||||
existing_value = (void *)existing_entry->v;
|
||||
@@ -415,6 +416,7 @@ void json_object_object_add(struct json_object* jso, const char *key,
|
||||
existing_entry->v = val;
|
||||
}
|
||||
|
||||
|
||||
int json_object_object_length(struct json_object *jso)
|
||||
{
|
||||
return lh_table_length(jso->o.c_object);
|
||||
|
||||
Reference in New Issue
Block a user