Permalink
Browse files

Replace hex table with some fairly small logic. Should have fewer mem…

…ory accesses, which is nice.
  • Loading branch information...
1 parent b31f55d commit db9c326f74709b5a5f2904e11f44b9c165613433 @PeterScott PeterScott committed Feb 12, 2012
Showing with 4 additions and 11 deletions.
  1. +4 −11 json.c
View
15 json.c
@@ -45,19 +45,12 @@ typedef unsigned short json_uchar;
#define numeric(b) \
((b) >= '0' && (b) <= '9')
-static const unsigned char hex_table [] =
-{
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10,
- 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
-};
-
static unsigned char hex_value (json_char c)
{
- return c > 127 ? 0xFF : hex_table [c];
+ if (c >= 48 && c <= 57) return c - 48;
+ if (c >= 65 && c <= 70) return c - 55;
+ if (c >= 97 && c <= 102) return c - 87;
+ return -1;
}
typedef struct

0 comments on commit db9c326

Please sign in to comment.