Skip to content

Commit 432875f

Browse files
committed
Optimize parsing hex digits.
1 parent d1bb99d commit 432875f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

json_parser.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,14 @@ static int __parse_json_hex4(const char *cursor, const char **end,
127127
hex = *cursor;
128128
if (hex >= '0' && hex <= '9')
129129
hex = hex - '0';
130-
else if (hex >= 'A' && hex <= 'F')
131-
hex = hex - 'A' + 10;
132-
else if (hex >= 'a' && hex <= 'f')
133-
hex = hex - 'a' + 10;
134130
else
135-
return -2;
131+
{
132+
hex |= 0x20;
133+
if (hex >= 'a' && hex <= 'f')
134+
hex = hex - 'a' + 10;
135+
else
136+
return -2;
137+
}
136138

137139
*code = (*code << 4) + hex;
138140
cursor++;

0 commit comments

Comments
 (0)