diff --git a/benchmark/parsingcompetition.cpp b/benchmark/parsingcompetition.cpp index dca069e32..ba4dad71d 100644 --- a/benchmark/parsingcompetition.cpp +++ b/benchmark/parsingcompetition.cpp @@ -46,6 +46,7 @@ int main(int argc, char *argv[]) { int repeat = 10; int volume = p.second; BEST_TIME(json_parse(p.first, p.second, pj), true, , repeat, volume, true); + BEST_TIME(json_parse_4stages(p.first, p.second, pj), true, , repeat, volume, true); rapidjson::Document d; diff --git a/include/jsonparser/jsonparser.h b/include/jsonparser/jsonparser.h index c950927cc..cde459ec0 100644 --- a/include/jsonparser/jsonparser.h +++ b/include/jsonparser/jsonparser.h @@ -21,3 +21,6 @@ void deallocate_ParsedJson(ParsedJson *pj_ptr); // Parse a document found in buf, need to preallocate ParsedJson. // Return false in case of a failure. bool json_parse(const u8 *buf, size_t len, ParsedJson &pj); + +// like json_parse but users 4 stages, slower. +bool json_parse_4stages(const u8 *buf, size_t len, ParsedJson &pj); \ No newline at end of file diff --git a/src/jsonparser.cpp b/src/jsonparser.cpp index 4e00f14ef..def9f4362 100644 --- a/src/jsonparser.cpp +++ b/src/jsonparser.cpp @@ -44,8 +44,9 @@ void deallocate_ParsedJson(ParsedJson *pj_ptr) { delete pj_ptr; } -// parse a document found in buf, need to preallocate ParsedJson. -bool json_parse(const u8 *buf, size_t len, ParsedJson &pj) { +// parse a document found in buf, need to preallocate ParsedJson. +// this can probably be considered a legacy function at this point. +bool json_parse_4stages(const u8 *buf, size_t len, ParsedJson &pj) { if (pj.bytecapacity < len) { std::cerr << "Your ParsedJson cannot support documents that big: " << len << std::endl; @@ -63,3 +64,21 @@ bool json_parse(const u8 *buf, size_t len, ParsedJson &pj) { } return isok; } + +// parse a document found in buf, need to preallocate ParsedJson. +bool json_parse(const u8 *buf, size_t len, ParsedJson &pj) { + if (pj.bytecapacity < len) { + std::cerr << "Your ParsedJson cannot support documents that big: " << len + << std::endl; + return false; + } + bool isok = find_structural_bits(buf, len, pj); + if (isok) { + isok = flatten_indexes(len, pj); + } + if (isok) { + isok = unified_machine(buf, len, pj); + } + return isok; +} +