Update cJSON from 1.7.13 to 1.7.14 (released 3 September 2020). The structure of linkedlist has been changed to improve the efficiency of adding items to arrays/objects.
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
3f918fec95
commit
fd2f8d7926
|
@ -92,7 +92,7 @@ CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void)
|
|||
return (const char*) (global_error.json + global_error.position);
|
||||
}
|
||||
|
||||
CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item)
|
||||
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item)
|
||||
{
|
||||
if (!cJSON_IsString(item))
|
||||
{
|
||||
|
@ -102,18 +102,18 @@ CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item)
|
|||
return item->valuestring;
|
||||
}
|
||||
|
||||
CJSON_PUBLIC(double) cJSON_GetNumberValue(cJSON *item)
|
||||
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item)
|
||||
{
|
||||
if (!cJSON_IsNumber(item))
|
||||
{
|
||||
return NAN;
|
||||
return (double) NAN;
|
||||
}
|
||||
|
||||
return item->valuedouble;
|
||||
}
|
||||
|
||||
/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
|
||||
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 13)
|
||||
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 14)
|
||||
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
|
||||
#endif
|
||||
|
||||
|
@ -1509,6 +1509,10 @@ static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buf
|
|||
success:
|
||||
input_buffer->depth--;
|
||||
|
||||
if (head != NULL) {
|
||||
head->prev = current_item;
|
||||
}
|
||||
|
||||
item->type = cJSON_Array;
|
||||
item->child = head;
|
||||
|
||||
|
@ -1681,6 +1685,10 @@ static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_bu
|
|||
success:
|
||||
input_buffer->depth--;
|
||||
|
||||
if (head != NULL) {
|
||||
head->prev = current_item;
|
||||
}
|
||||
|
||||
item->type = cJSON_Object;
|
||||
item->child = head;
|
||||
|
||||
|
@ -1967,15 +1975,6 @@ static cJSON_bool add_item_to_array(cJSON *array, cJSON *item)
|
|||
suffix_object(child->prev, item);
|
||||
array->child->prev = item;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (child->next)
|
||||
{
|
||||
child = child->next;
|
||||
}
|
||||
suffix_object(child, item);
|
||||
array->child->prev = item;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -2202,6 +2201,12 @@ CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const it
|
|||
/* first element */
|
||||
parent->child = item->next;
|
||||
}
|
||||
else if (item->next == NULL)
|
||||
{
|
||||
/* last element */
|
||||
parent->child->prev = item->prev;
|
||||
}
|
||||
|
||||
/* make sure the detached item doesn't point anywhere anymore */
|
||||
item->prev = NULL;
|
||||
item->next = NULL;
|
||||
|
@ -2299,6 +2304,10 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON
|
|||
}
|
||||
if (parent->child == item)
|
||||
{
|
||||
if (parent->child->prev == parent->child)
|
||||
{
|
||||
replacement->prev = replacement;
|
||||
}
|
||||
parent->child = replacement;
|
||||
}
|
||||
else
|
||||
|
@ -2310,6 +2319,10 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON
|
|||
{
|
||||
replacement->prev->next = replacement;
|
||||
}
|
||||
if (replacement->next == NULL)
|
||||
{
|
||||
parent->child->prev = replacement;
|
||||
}
|
||||
}
|
||||
|
||||
item->next = NULL;
|
||||
|
@ -2549,6 +2562,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count)
|
|||
}
|
||||
p = n;
|
||||
}
|
||||
a->child->prev = n;
|
||||
|
||||
return a;
|
||||
}
|
||||
|
@ -2585,6 +2599,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count)
|
|||
}
|
||||
p = n;
|
||||
}
|
||||
a->child->prev = n;
|
||||
|
||||
return a;
|
||||
}
|
||||
|
@ -2621,6 +2636,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count)
|
|||
}
|
||||
p = n;
|
||||
}
|
||||
a->child->prev = n;
|
||||
|
||||
return a;
|
||||
}
|
||||
|
@ -2657,6 +2673,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int co
|
|||
}
|
||||
p = n;
|
||||
}
|
||||
a->child->prev = n;
|
||||
|
||||
return a;
|
||||
}
|
||||
|
@ -2729,6 +2746,10 @@ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse)
|
|||
}
|
||||
child = child->next;
|
||||
}
|
||||
if (newitem && newitem->child)
|
||||
{
|
||||
newitem->child->prev = newchild;
|
||||
}
|
||||
|
||||
return newitem;
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJ
|
|||
/* project version */
|
||||
#define CJSON_VERSION_MAJOR 1
|
||||
#define CJSON_VERSION_MINOR 7
|
||||
#define CJSON_VERSION_PATCH 13
|
||||
#define CJSON_VERSION_PATCH 14
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
@ -176,8 +176,8 @@ CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *st
|
|||
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
|
||||
|
||||
/* Check item type and return its value */
|
||||
CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item);
|
||||
CJSON_PUBLIC(double) cJSON_GetNumberValue(cJSON *item);
|
||||
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
|
||||
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);
|
||||
|
||||
/* These functions check the type of an item */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
|
||||
|
|
Loading…
Reference in New Issue