From 2f6c9199867248069b1992c413f1e695b035cc39 Mon Sep 17 00:00:00 2001 From: Joel Vandergriendt Date: Thu, 29 Mar 2018 13:33:51 -0700 Subject: [PATCH 1/2] speed up large arrays --- tiny-json.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tiny-json.c b/tiny-json.c index 12a1b9a..cf0f7d2 100644 --- a/tiny-json.c +++ b/tiny-json.c @@ -300,11 +300,12 @@ static char* numValue( char* ptr, json_t* property ) { * @param property The handler of the property to be added. */ static void add( json_t* obj, json_t* property ) { property->sibling = 0; - if ( !obj->u.child ) obj->u.child = property; - else { - json_t* iter; - for( iter = obj->u.child; iter->sibling; iter = iter->sibling ); - iter->sibling = property; + if ( !obj->u.child ){ + obj->u.child = property; + obj->u.last_child = property; + } else { + obj->u.last_child->sibling = property; + obj->u.last_child = property; } } From a2fdcc20e03d7ce25b768eb70ff405dfd1966847 Mon Sep 17 00:00:00 2001 From: Joel Vandergriendt Date: Thu, 29 Mar 2018 13:33:54 -0700 Subject: [PATCH 2/2] speed up large arrays --- tiny-json.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tiny-json.h b/tiny-json.h index 78e4e19..365ce7a 100644 --- a/tiny-json.h +++ b/tiny-json.h @@ -43,7 +43,10 @@ typedef struct json_s { char const* name; union { char const* value; - struct json_s* child; + struct { + struct json_s* child; + struct json_s* last_child; + }; } u; jsonType_t type; } json_t;