mirror of
https://github.com/json-c/json-c.git
synced 2026-04-05 13:29:06 +08:00
json_tokener: optimize check for whitespace characters
speedup for 32-bit: ~15% speedup for 64-bit: ~ 2%
This commit is contained in:
@@ -50,6 +50,22 @@
|
|||||||
# error You do not have strncasecmp on your system.
|
# error You do not have strncasecmp on your system.
|
||||||
#endif /* HAVE_STRNCASECMP */
|
#endif /* HAVE_STRNCASECMP */
|
||||||
|
|
||||||
|
/* The following helper functions are used to speed up parsing. They
|
||||||
|
* are faster than their ctype counterparts because they assume that
|
||||||
|
* the input is in ASCII and that the locale is set to "C". The
|
||||||
|
* compiler will also inline these functions, providing an additional
|
||||||
|
* speedup by saving on function calls.
|
||||||
|
*/
|
||||||
|
static int is_ws_char(char c)
|
||||||
|
{
|
||||||
|
return c == ' '
|
||||||
|
|| c == '\t'
|
||||||
|
|| c == '\n'
|
||||||
|
|| c == '\v'
|
||||||
|
|| c == '\f'
|
||||||
|
|| c == '\r';
|
||||||
|
}
|
||||||
|
|
||||||
/* Use C99 NAN by default; if not available, nan("") should work too. */
|
/* Use C99 NAN by default; if not available, nan("") should work too. */
|
||||||
#ifndef NAN
|
#ifndef NAN
|
||||||
#define NAN nan("")
|
#define NAN nan("")
|
||||||
@@ -295,7 +311,7 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
|
|||||||
|
|
||||||
case json_tokener_state_eatws:
|
case json_tokener_state_eatws:
|
||||||
/* Advance until we change state */
|
/* Advance until we change state */
|
||||||
while (isspace((unsigned char)c)) {
|
while (is_ws_char(c)) {
|
||||||
if ((!ADVANCE_CHAR(str, tok)) || (!PEEK_CHAR(c, tok)))
|
if ((!ADVANCE_CHAR(str, tok)) || (!PEEK_CHAR(c, tok)))
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user