Rework cJSON_Utils object compare functions to use an O(N) algorithm on sorted lists.

It's a bit of a shame to use the sorts, because cJSON is otherwise incredibly stable (json->cJSON->json is unmodified modulo formatting),
but it means we get usable performance, rather than O(N^2) which will make CPUs cry.


git-svn-id: svn://svn.code.sf.net/p/cjson/code@71 e3330c51-1366-4df0-8b21-3ccf24e3d50e
This commit is contained in:
Dave Gamble
2015-02-13 19:53:27 +00:00
parent c4ddd7aaa3
commit 491cf029b2
2 changed files with 32 additions and 23 deletions

View File

@@ -101,9 +101,9 @@ int main()
{
buf[0]=random[i];cJSON_AddItemToObject(sortme,buf,cJSON_CreateNumber(1));
}
before=cJSON_Print(sortme);
before=cJSON_PrintUnformatted(sortme);
cJSONUtils_SortObject(sortme);
after=cJSON_Print(sortme);
after=cJSON_PrintUnformatted(sortme);
printf("Before: [%s]\nAfter: [%s]\n\n",before,after);
free(before);free(after);cJSON_Delete(sortme);
}