diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-11-16 13:14:14 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-11-16 13:14:14 +0100 |
commit | ff441aa908ad48ab5d197f4efd7d6e879fe185a2 (patch) | |
tree | 51437597c2c27b7a1d86a2ac36989efc2624ef38 | |
parent | 181fde5208efa0d45126327dd0c4197e1a63fd90 (diff) |
lib: optimize length() for objects
Instead of counting the keys individually, use the existing
json_object_object_length() function.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | lib.c | 11 |
1 files changed, 1 insertions, 10 deletions
@@ -368,19 +368,10 @@ static struct json_object * ut_length(struct ut_state *s, uint32_t off, struct json_object *args) { struct json_object *arg = json_object_array_get_idx(args, 0); - size_t len; switch (json_object_get_type(arg)) { case json_type_object: - len = 0; - - json_object_object_foreach(arg, k, v) { - (void)k; - (void)v; - len++; - } - - return xjs_new_int64(len); + return xjs_new_int64(json_object_object_length(arg)); case json_type_array: return xjs_new_int64(json_object_array_length(arg)); |