]> granicus.if.org Git - json-c/commitdiff
json_tokener: optimize check for number characters
authorRamiro Polla <ramiro.polla@gmail.com>
Sat, 8 Dec 2018 18:17:25 +0000 (19:17 +0100)
committerRamiro Polla <ramiro.polla@gmail.com>
Thu, 20 Dec 2018 23:24:17 +0000 (00:24 +0100)
speedup for 32-bit: ~5%
speedup for 64-bit: ~3%

json_object.c
json_object_private.h
json_tokener.c

index e3c5744d906de973ae387b998eac72662830bddb..cea5245e5eea7bda3b6ca633c7b539d717204052 100644 (file)
@@ -41,7 +41,6 @@
 // Don't define this.  It's not thread-safe.
 /* #define REFCOUNT_DEBUG 1 */
 
-const char *json_number_chars = "0123456789.+-eE";
 const char *json_hex_chars = "0123456789abcdefABCDEF";
 
 static struct json_object* json_object_new(enum json_type o_type);
index d964b16272f4f9acbaec436ff1bececedbd2d0e2..a023a85a85f32bfaf8d771ae01f36d7accffe934 100644 (file)
@@ -51,7 +51,6 @@ struct json_object
 
 void _json_c_set_last_err(const char *err_fmt, ...);
 
-extern const char *json_number_chars;
 extern const char *json_hex_chars;
 
 #ifdef __cplusplus
index b3b28b6bcc7feaada4845f8a14aa5e3c286d736c..b5fb21043910b0a50e5c3ac3a4e0bbe72a2fd465 100644 (file)
@@ -73,6 +73,16 @@ static int is_hex_char(char c)
            || (c >= 'a' && c <= 'f');
 }
 
+static int is_number_char(char c)
+{
+       return (c >= '0' && c <= '9')
+           || c == '.'
+           || c == '+'
+           || c == '-'
+           || c == 'e'
+           || c == 'E';
+}
+
 /* Use C99 NAN by default; if not available, nan("") should work too. */
 #ifndef NAN
 #define NAN nan("")
@@ -757,7 +767,7 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
        int case_len=0;
        int is_exponent=0;
        int negativesign_next_possible_location=1;
-       while(c && strchr(json_number_chars, c)) {
+       while(c && is_number_char(c)) {
          ++case_len;
 
          /* non-digit characters checks */