mirror of
https://github.com/json-c/json-c.git
synced 2026-03-20 21:49:07 +08:00
json_tokener: optimize check for hex characters
speedup for 32-bit: ~1% speedup for 64-bit: ~1%
This commit is contained in:
@@ -66,6 +66,13 @@ static int is_ws_char(char c)
|
||||
|| c == '\r';
|
||||
}
|
||||
|
||||
static int is_hex_char(char c)
|
||||
{
|
||||
return (c >= '0' && c <= '9')
|
||||
|| (c >= 'A' && c <= 'F')
|
||||
|| (c >= 'a' && c <= 'f');
|
||||
}
|
||||
|
||||
/* Use C99 NAN by default; if not available, nan("") should work too. */
|
||||
#ifndef NAN
|
||||
#define NAN nan("")
|
||||
@@ -609,7 +616,7 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
|
||||
|
||||
/* Handle a 4-byte sequence, or two sequences if a surrogate pair */
|
||||
while(1) {
|
||||
if (c && strchr(json_hex_chars, c)) {
|
||||
if (c && is_hex_char(c)) {
|
||||
tok->ucs_char += ((unsigned int)jt_hexdigit(c) << ((3-tok->st_pos++)*4));
|
||||
if(tok->st_pos == 4) {
|
||||
unsigned char unescaped_utf[4];
|
||||
@@ -641,7 +648,7 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
|
||||
got_hi_surrogate = tok->ucs_char;
|
||||
/* Not at end, and the next two chars should be "\u" */
|
||||
if ((len == -1 || len > (tok->char_offset + 2)) &&
|
||||
// str[0] != '0' && // implied by json_hex_chars, above.
|
||||
// str[0] != '0' && // implied by is_hex_char, above.
|
||||
(str[1] == '\\') &&
|
||||
(str[2] == 'u'))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user