From ee6647ce4006b655be19955a5b941dd7deda8e2d Mon Sep 17 00:00:00 2001 From: John Keiser Date: Mon, 3 Aug 2020 15:47:31 -0700 Subject: [PATCH] Make parse part of structural_parser --- src/arm64/dom_parser_implementation.cpp | 5 +++-- src/fallback/dom_parser_implementation.cpp | 5 +++-- src/generic/stage2/structural_parser.h | 18 ++++++------------ src/haswell/dom_parser_implementation.cpp | 5 +++-- src/westmere/dom_parser_implementation.cpp | 5 +++-- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/arm64/dom_parser_implementation.cpp b/src/arm64/dom_parser_implementation.cpp index 1e706377..62609b5f 100644 --- a/src/arm64/dom_parser_implementation.cpp +++ b/src/arm64/dom_parser_implementation.cpp @@ -112,6 +112,7 @@ really_inline simd8 must_be_2_3_continuation(const simd8 prev2, c #include "arm64/stringparsing.h" #include "arm64/numberparsing.h" #include "generic/stage2/structural_parser.h" +#include "generic/stage2/tape_builder.h" // // Implementation-specific overrides @@ -144,7 +145,7 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons } WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept { - if (auto error = stage2::parse_structurals(*this, _doc)) { return error; } + if (auto error = stage2::structural_parser::parse(*this, _doc)) { return error; } // If we didn't make it to the end, it's an error if ( next_structural_index != n_structural_indexes ) { @@ -156,7 +157,7 @@ WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) no } WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept { - return stage2::parse_structurals(*this, _doc); + return stage2::structural_parser::parse(*this, _doc); } 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 d00c3783..24d4648a 100644 --- a/src/fallback/dom_parser_implementation.cpp +++ b/src/fallback/dom_parser_implementation.cpp @@ -316,12 +316,13 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons #include "fallback/stringparsing.h" #include "fallback/numberparsing.h" #include "generic/stage2/structural_parser.h" +#include "generic/stage2/tape_builder.h" namespace { namespace SIMDJSON_IMPLEMENTATION { WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept { - if (auto error = stage2::parse_structurals(*this, _doc)) { return error; } + if (auto error = stage2::structural_parser::parse(*this, _doc)) { return error; } // If we didn't make it to the end, it's an error if ( next_structural_index != n_structural_indexes ) { @@ -333,7 +334,7 @@ WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) no } WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept { - return stage2::parse_structurals(*this, _doc); + return stage2::structural_parser::parse(*this, _doc); } 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 11ac161a..c8e2b55a 100644 --- a/src/generic/stage2/structural_parser.h +++ b/src/generic/stage2/structural_parser.h @@ -19,6 +19,9 @@ struct structural_parser : structural_iterator { /** Current depth (nested objects and arrays) */ uint32_t depth{0}; + template + WARN_UNUSED static really_inline error_code parse(dom_parser_implementation &dom_parser, dom::document &doc) noexcept; + // For non-streaming, to pass an explicit 0 as next_structural, which enables optimizations really_inline structural_parser(dom_parser_implementation &_parser, uint32_t start_structural_index) : structural_iterator(_parser, start_structural_index), @@ -149,20 +152,11 @@ struct structural_parser : structural_iterator { } }; // struct structural_parser -} // namespace stage2 -} // namespace SIMDJSON_IMPLEMENTATION -} // unnamed namespace - -#include "generic/stage2/tape_builder.h" - -namespace { // Make everything here private -namespace SIMDJSON_IMPLEMENTATION { -namespace stage2 { - +template template -WARN_UNUSED static really_inline error_code parse_structurals(dom_parser_implementation &dom_parser, dom::document &doc) noexcept { +WARN_UNUSED really_inline error_code structural_parser::parse(dom_parser_implementation &dom_parser, dom::document &doc) noexcept { dom_parser.doc = &doc; - stage2::structural_parser parser(dom_parser, STREAMING ? dom_parser.next_structural_index : 0); + stage2::structural_parser parser(dom_parser, STREAMING ? dom_parser.next_structural_index : 0); SIMDJSON_TRY( parser.start() ); // diff --git a/src/haswell/dom_parser_implementation.cpp b/src/haswell/dom_parser_implementation.cpp index 1b5ca5bf..9434ffd3 100644 --- a/src/haswell/dom_parser_implementation.cpp +++ b/src/haswell/dom_parser_implementation.cpp @@ -77,6 +77,7 @@ really_inline simd8 must_be_2_3_continuation(const simd8 prev2, c #include "haswell/stringparsing.h" #include "haswell/numberparsing.h" #include "generic/stage2/structural_parser.h" +#include "generic/stage2/tape_builder.h" // // Implementation-specific overrides @@ -107,7 +108,7 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons } WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept { - if (auto error = stage2::parse_structurals(*this, _doc)) { return error; } + if (auto error = stage2::structural_parser::parse(*this, _doc)) { return error; } // If we didn't make it to the end, it's an error if ( next_structural_index != n_structural_indexes ) { @@ -119,7 +120,7 @@ WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) no } WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept { - return stage2::parse_structurals(*this, _doc); + return stage2::structural_parser::parse(*this, _doc); } 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 71981947..32b863a7 100644 --- a/src/westmere/dom_parser_implementation.cpp +++ b/src/westmere/dom_parser_implementation.cpp @@ -82,6 +82,7 @@ really_inline simd8 must_be_2_3_continuation(const simd8 prev2, c #include "westmere/stringparsing.h" #include "westmere/numberparsing.h" #include "generic/stage2/structural_parser.h" +#include "generic/stage2/tape_builder.h" // // Implementation-specific overrides @@ -113,7 +114,7 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons } WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept { - if (auto error = stage2::parse_structurals(*this, _doc)) { return error; } + if (auto error = stage2::structural_parser::parse(*this, _doc)) { return error; } // If we didn't make it to the end, it's an error if ( next_structural_index != n_structural_indexes ) { @@ -125,7 +126,7 @@ WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) no } WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept { - return stage2::parse_structurals(*this, _doc); + return stage2::structural_parser::parse(*this, _doc); } WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept {