mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
Parse least common datatype last
Null types are almost certainly the least common object, so putting the check last in the list will be faster. This gave an approximate 5% performance improvement in parse_value() in tests.
This commit is contained in:
parent
cb8693b058
commit
bb27ffa152
14
cJSON.c
14
cJSON.c
@ -1317,13 +1317,6 @@ static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buf
|
||||
}
|
||||
|
||||
/* parse the different types of values */
|
||||
/* null */
|
||||
if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "null", 4) == 0))
|
||||
{
|
||||
item->type = cJSON_NULL;
|
||||
input_buffer->offset += 4;
|
||||
return true;
|
||||
}
|
||||
/* false */
|
||||
if (can_read(input_buffer, 5) && (strncmp((const char*)buffer_at_offset(input_buffer), "false", 5) == 0))
|
||||
{
|
||||
@ -1359,6 +1352,13 @@ static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buf
|
||||
{
|
||||
return parse_object(item, input_buffer);
|
||||
}
|
||||
/* null */
|
||||
if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "null", 4) == 0))
|
||||
{
|
||||
item->type = cJSON_NULL;
|
||||
input_buffer->offset += 4;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user