Merge pull request #1 from vanjoe/master

Speed up adding of large arrays.
This commit is contained in:
rafagafe 2018-04-10 22:29:50 +02:00 committed by GitHub
commit 2e98dd7e63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -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;
}
}

View File

@ -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;