mirror of
https://github.com/json-c/json-c.git
synced 2026-04-11 08:19:08 +08:00
Add json_object_array_shrink() (and array_list_shrink()) and use it in json_tokener to minimize the amount of memory used. This results in a 39%-50% reduction in memory use (peak RSS, peak heap usage) on the jc-bench benchmark and 9% shorter runtime.
Also add the json_object_new_array_ext, array_list_new2, and array_list_shrink functions.
This commit is contained in:
@@ -964,6 +964,9 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
|
||||
case json_tokener_state_array:
|
||||
if (c == ']')
|
||||
{
|
||||
// Minimize memory usage; assume parsed objs are unlikely to be changed
|
||||
json_object_array_shrink(current, 0);
|
||||
|
||||
if (state == json_tokener_state_array_after_sep &&
|
||||
(tok->flags & JSON_TOKENER_STRICT))
|
||||
{
|
||||
@@ -997,6 +1000,9 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
|
||||
case json_tokener_state_array_sep:
|
||||
if (c == ']')
|
||||
{
|
||||
// Minimize memory usage; assume parsed objs are unlikely to be changed
|
||||
json_object_array_shrink(current, 0);
|
||||
|
||||
saved_state = json_tokener_state_finish;
|
||||
state = json_tokener_state_eatws;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user