From 7fda77d51aa73e7eafef05503cbd7e27b13fe06a Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Mon, 10 Dec 2018 15:35:42 -0500 Subject: [PATCH] Mostly fixed performance regression. --- include/simdjson/jsoncharutils.h | 17 +++++++++++++++++ include/simdjson/numberparsing.h | 9 +++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/simdjson/jsoncharutils.h b/include/simdjson/jsoncharutils.h index 68da3735..8fa1b3a9 100644 --- a/include/simdjson/jsoncharutils.h +++ b/include/simdjson/jsoncharutils.h @@ -33,6 +33,23 @@ really_inline u32 is_not_structural_or_whitespace(u8 c) { return structural_or_whitespace_negated[c]; } +const u32 structural_or_whitespace[256] = { + 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +really_inline u32 is_structural_or_whitespace(u8 c) { + return structural_or_whitespace[c]; +} + const char digittoval[256] = { -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, diff --git a/include/simdjson/numberparsing.h b/include/simdjson/numberparsing.h index a38cb02c..3338edf7 100644 --- a/include/simdjson/numberparsing.h +++ b/include/simdjson/numberparsing.h @@ -250,7 +250,7 @@ parse_float(const u8 *const buf, #ifdef JSON_TEST_NUMBERS // for unit testing foundFloat(d, buf + offset); #endif - return true; + return is_structural_or_whitespace(*p); } // called by parse_number when we know that the output is an integer, @@ -321,7 +321,7 @@ static never_inline bool parse_large_integer(const u8 *const buf, #ifdef JSON_TEST_NUMBERS // for unit testing foundInteger(signed_answer, buf + offset); #endif - return true; + return is_structural_or_whitespace(*p); } #ifndef likely @@ -450,9 +450,6 @@ static really_inline bool parse_number(const u8 *const buf, } exponent += (negexp ? -expnumber : expnumber); } - if(is_not_structural_or_whitespace(*p)) { - return false; - } i = negative ? -i : i; if ((exponent != 0) || (expnumber != 0)) { if (unlikely(digitcount >= 19)) { // this is uncommon!!! @@ -495,5 +492,5 @@ static really_inline bool parse_number(const u8 *const buf, foundInteger(i, buf + offset); #endif } - return true; + return is_structural_or_whitespace(*p); }