From 04d39c0961c22e28e3e2a36c4ac80c8d84e9df33 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Thu, 6 Aug 2020 09:48:36 -0700 Subject: [PATCH] Make tape_builder primary entry point to stage 2 --- src/arm64/dom_parser_implementation.cpp | 9 ++------- src/fallback/dom_parser_implementation.cpp | 9 ++------- src/generic/stage2/structural_parser.h | 9 ++------- src/generic/stage2/tape_builder.h | 13 ++++++++++++- src/haswell/dom_parser_implementation.cpp | 9 ++------- src/westmere/dom_parser_implementation.cpp | 9 ++------- 6 files changed, 22 insertions(+), 36 deletions(-) diff --git a/src/arm64/dom_parser_implementation.cpp b/src/arm64/dom_parser_implementation.cpp index fa04af9c..91acc20d 100644 --- a/src/arm64/dom_parser_implementation.cpp +++ b/src/arm64/dom_parser_implementation.cpp @@ -111,7 +111,6 @@ simdjson_really_inline simd8 must_be_2_3_continuation(const simd8 #include "arm64/stringparsing.h" #include "arm64/numberparsing.h" -#include "generic/stage2/structural_parser.h" #include "generic/stage2/tape_builder.h" // @@ -145,15 +144,11 @@ SIMDJSON_WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t } SIMDJSON_WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept { - doc = &_doc; - stage2::tape_builder builder(*doc); - return stage2::structural_parser::parse(*this, builder); + return stage2::tape_builder::parse_document(*this, _doc); } SIMDJSON_WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept { - doc = &_doc; - stage2::tape_builder builder(_doc); - return stage2::structural_parser::parse(*this, builder); + return stage2::tape_builder::parse_document(*this, _doc); } SIMDJSON_WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept { diff --git a/src/fallback/dom_parser_implementation.cpp b/src/fallback/dom_parser_implementation.cpp index 24b13a2d..a348fbdd 100644 --- a/src/fallback/dom_parser_implementation.cpp +++ b/src/fallback/dom_parser_implementation.cpp @@ -315,22 +315,17 @@ SIMDJSON_WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t // #include "fallback/stringparsing.h" #include "fallback/numberparsing.h" -#include "generic/stage2/structural_parser.h" #include "generic/stage2/tape_builder.h" namespace { namespace SIMDJSON_IMPLEMENTATION { SIMDJSON_WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept { - doc = &_doc; - stage2::tape_builder builder(*doc); - return stage2::structural_parser::parse(*this, builder); + return stage2::tape_builder::parse_document(*this, _doc); } SIMDJSON_WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept { - doc = &_doc; - stage2::tape_builder builder(_doc); - return stage2::structural_parser::parse(*this, builder); + return stage2::tape_builder::parse_document(*this, _doc); } SIMDJSON_WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept { diff --git a/src/generic/stage2/structural_parser.h b/src/generic/stage2/structural_parser.h index 101b2f1b..04812dac 100644 --- a/src/generic/stage2/structural_parser.h +++ b/src/generic/stage2/structural_parser.h @@ -17,12 +17,7 @@ struct structural_parser : structural_iterator { uint32_t depth{0}; template - SIMDJSON_WARN_UNUSED simdjson_really_inline error_code parse(T &builder) noexcept; - template - SIMDJSON_WARN_UNUSED static simdjson_really_inline error_code parse(dom_parser_implementation &dom_parser, T &builder) noexcept { - structural_parser parser(dom_parser, STREAMING ? dom_parser.next_structural_index : 0); - return parser.parse(builder); - } + SIMDJSON_WARN_UNUSED simdjson_really_inline error_code walk_document(T &builder) noexcept; // For non-streaming, to pass an explicit 0 as next_structural, which enables optimizations simdjson_really_inline structural_parser(dom_parser_implementation &_dom_parser, uint32_t start_structural_index) @@ -90,7 +85,7 @@ struct structural_parser : structural_iterator { }; // struct structural_parser template -SIMDJSON_WARN_UNUSED simdjson_really_inline error_code structural_parser::parse(T &builder) noexcept { +SIMDJSON_WARN_UNUSED simdjson_really_inline error_code structural_parser::walk_document(T &builder) noexcept { logger::log_start(); // diff --git a/src/generic/stage2/tape_builder.h b/src/generic/stage2/tape_builder.h index 4e0ecefe..17ee3dc9 100644 --- a/src/generic/stage2/tape_builder.h +++ b/src/generic/stage2/tape_builder.h @@ -1,3 +1,4 @@ +#include "generic/stage2/structural_parser.h" #include "generic/stage2/tape_writer.h" #include "generic/stage2/atomparsing.h" @@ -11,11 +12,21 @@ struct tape_builder { /** Next write location in the string buf for stage 2 parsing */ uint8_t *current_string_buf_loc; - simdjson_really_inline tape_builder(dom::document &doc) noexcept : tape{doc.tape.get()}, current_string_buf_loc{doc.string_buf.get()} {} + template + SIMDJSON_WARN_UNUSED static simdjson_really_inline error_code parse_document( + dom_parser_implementation &dom_parser, + dom::document &doc) noexcept { + dom_parser.doc = &doc; + structural_parser iter(dom_parser, STREAMING ? dom_parser.next_structural_index : 0); + tape_builder builder(doc); + return iter.walk_document(builder); + } private: friend struct structural_parser; + simdjson_really_inline tape_builder(dom::document &doc) noexcept : tape{doc.tape.get()}, current_string_buf_loc{doc.string_buf.get()} {} + simdjson_really_inline error_code parse_root_primitive(structural_parser &parser, const uint8_t *value) { switch (*value) { case '"': return parse_string(parser, value); diff --git a/src/haswell/dom_parser_implementation.cpp b/src/haswell/dom_parser_implementation.cpp index cad3b7fb..de436d9c 100644 --- a/src/haswell/dom_parser_implementation.cpp +++ b/src/haswell/dom_parser_implementation.cpp @@ -80,7 +80,6 @@ simdjson_really_inline simd8 must_be_2_3_continuation(const simd8 // #include "haswell/stringparsing.h" #include "haswell/numberparsing.h" -#include "generic/stage2/structural_parser.h" #include "generic/stage2/tape_builder.h" // @@ -112,15 +111,11 @@ SIMDJSON_WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t } SIMDJSON_WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept { - doc = &_doc; - stage2::tape_builder builder(_doc); - return stage2::structural_parser::parse(*this, builder); + return stage2::tape_builder::parse_document(*this, _doc); } SIMDJSON_WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept { - doc = &_doc; - stage2::tape_builder builder(_doc); - return stage2::structural_parser::parse(*this, builder); + return stage2::tape_builder::parse_document(*this, _doc); } SIMDJSON_WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept { diff --git a/src/westmere/dom_parser_implementation.cpp b/src/westmere/dom_parser_implementation.cpp index d8ec666b..55c61b8d 100644 --- a/src/westmere/dom_parser_implementation.cpp +++ b/src/westmere/dom_parser_implementation.cpp @@ -81,7 +81,6 @@ simdjson_really_inline simd8 must_be_2_3_continuation(const simd8 // #include "westmere/stringparsing.h" #include "westmere/numberparsing.h" -#include "generic/stage2/structural_parser.h" #include "generic/stage2/tape_builder.h" // @@ -114,15 +113,11 @@ SIMDJSON_WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t } SIMDJSON_WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept { - doc = &_doc; - stage2::tape_builder builder(*doc); - return stage2::structural_parser::parse(*this, builder); + return stage2::tape_builder::parse_document(*this, _doc); } SIMDJSON_WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept { - doc = &_doc; - stage2::tape_builder builder(_doc); - return stage2::structural_parser::parse(*this, builder); + return stage2::tape_builder::parse_document(*this, _doc); } SIMDJSON_WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept {