mirror of
https://github.com/json-c/json-c.git
synced 2026-04-06 13:59:07 +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:
@@ -500,10 +500,16 @@ JSON_EXPORT void json_object_object_del(struct json_object *obj, const char *key
|
||||
/* Array type methods */
|
||||
|
||||
/** Create a new empty json_object of type json_type_array
|
||||
* If you know the array size you'll need ahead of time, use
|
||||
* json_object_new_array_ext() instead.
|
||||
* @see json_object_new_array_ext()
|
||||
* @see json_object_array_shrink()
|
||||
* @returns a json_object of type json_type_array
|
||||
*/
|
||||
JSON_EXPORT struct json_object *json_object_new_array(void);
|
||||
|
||||
JSON_EXPORT struct json_object *json_object_new_array_ext(int initial_size);
|
||||
|
||||
/** Get the arraylist of a json_object of type json_type_array
|
||||
* @param obj the json_object instance
|
||||
* @returns an arraylist
|
||||
@@ -595,6 +601,15 @@ JSON_EXPORT struct json_object *json_object_array_get_idx(const struct json_obje
|
||||
*/
|
||||
JSON_EXPORT int json_object_array_del_idx(struct json_object *obj, size_t idx, size_t count);
|
||||
|
||||
/**
|
||||
* Shrink the internal memory allocation of the array to just
|
||||
* enough to fit the number of elements in it, plus empty_slots.
|
||||
*
|
||||
* @param jso the json_object instance, must be json_type_array
|
||||
* @param empty_slots the number of empty slots to leave allocated
|
||||
*/
|
||||
JSON_EXPORT int json_object_array_shrink(struct json_object *jso, int empty_slots);
|
||||
|
||||
/* json_bool type methods */
|
||||
|
||||
/** Create a new empty json_object of type json_type_boolean
|
||||
|
||||
Reference in New Issue
Block a user