Skip to content

Commit ee6647c

Browse files
committed
Make parse part of structural_parser
1 parent 03d54f8 commit ee6647c

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

src/arm64/dom_parser_implementation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ really_inline simd8<bool> must_be_2_3_continuation(const simd8<uint8_t> prev2, c
112112
#include "arm64/stringparsing.h"
113113
#include "arm64/numberparsing.h"
114114
#include "generic/stage2/structural_parser.h"
115+
#include "generic/stage2/tape_builder.h"
115116

116117
//
117118
// Implementation-specific overrides
@@ -144,7 +145,7 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons
144145
}
145146

146147
WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept {
147-
if (auto error = stage2::parse_structurals<false>(*this, _doc)) { return error; }
148+
if (auto error = stage2::structural_parser<stage2::tape_builder>::parse<false>(*this, _doc)) { return error; }
148149

149150
// If we didn't make it to the end, it's an error
150151
if ( next_structural_index != n_structural_indexes ) {
@@ -156,7 +157,7 @@ WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) no
156157
}
157158

158159
WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept {
159-
return stage2::parse_structurals<true>(*this, _doc);
160+
return stage2::structural_parser<stage2::tape_builder>::parse<true>(*this, _doc);
160161
}
161162

162163
WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept {

src/fallback/dom_parser_implementation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,13 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons
316316
#include "fallback/stringparsing.h"
317317
#include "fallback/numberparsing.h"
318318
#include "generic/stage2/structural_parser.h"
319+
#include "generic/stage2/tape_builder.h"
319320

320321
namespace {
321322
namespace SIMDJSON_IMPLEMENTATION {
322323

323324
WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept {
324-
if (auto error = stage2::parse_structurals<false>(*this, _doc)) { return error; }
325+
if (auto error = stage2::structural_parser<stage2::tape_builder>::parse<false>(*this, _doc)) { return error; }
325326

326327
// If we didn't make it to the end, it's an error
327328
if ( next_structural_index != n_structural_indexes ) {
@@ -333,7 +334,7 @@ WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) no
333334
}
334335

335336
WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept {
336-
return stage2::parse_structurals<true>(*this, _doc);
337+
return stage2::structural_parser<stage2::tape_builder>::parse<true>(*this, _doc);
337338
}
338339

339340
WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept {

src/generic/stage2/structural_parser.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ struct structural_parser : structural_iterator {
1919
/** Current depth (nested objects and arrays) */
2020
uint32_t depth{0};
2121

22+
template<bool STREAMING>
23+
WARN_UNUSED static really_inline error_code parse(dom_parser_implementation &dom_parser, dom::document &doc) noexcept;
24+
2225
// For non-streaming, to pass an explicit 0 as next_structural, which enables optimizations
2326
really_inline structural_parser(dom_parser_implementation &_parser, uint32_t start_structural_index)
2427
: structural_iterator(_parser, start_structural_index),
@@ -149,20 +152,11 @@ struct structural_parser : structural_iterator {
149152
}
150153
}; // struct structural_parser
151154

152-
} // namespace stage2
153-
} // namespace SIMDJSON_IMPLEMENTATION
154-
} // unnamed namespace
155-
156-
#include "generic/stage2/tape_builder.h"
157-
158-
namespace { // Make everything here private
159-
namespace SIMDJSON_IMPLEMENTATION {
160-
namespace stage2 {
161-
155+
template<typename T>
162156
template<bool STREAMING>
163-
WARN_UNUSED static really_inline error_code parse_structurals(dom_parser_implementation &dom_parser, dom::document &doc) noexcept {
157+
WARN_UNUSED really_inline error_code structural_parser<T>::parse(dom_parser_implementation &dom_parser, dom::document &doc) noexcept {
164158
dom_parser.doc = &doc;
165-
stage2::structural_parser<stage2::tape_builder> parser(dom_parser, STREAMING ? dom_parser.next_structural_index : 0);
159+
stage2::structural_parser<T> parser(dom_parser, STREAMING ? dom_parser.next_structural_index : 0);
166160
SIMDJSON_TRY( parser.start() );
167161

168162
//

src/haswell/dom_parser_implementation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ really_inline simd8<bool> must_be_2_3_continuation(const simd8<uint8_t> prev2, c
7777
#include "haswell/stringparsing.h"
7878
#include "haswell/numberparsing.h"
7979
#include "generic/stage2/structural_parser.h"
80+
#include "generic/stage2/tape_builder.h"
8081

8182
//
8283
// Implementation-specific overrides
@@ -107,7 +108,7 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons
107108
}
108109

109110
WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept {
110-
if (auto error = stage2::parse_structurals<false>(*this, _doc)) { return error; }
111+
if (auto error = stage2::structural_parser<stage2::tape_builder>::parse<false>(*this, _doc)) { return error; }
111112

112113
// If we didn't make it to the end, it's an error
113114
if ( next_structural_index != n_structural_indexes ) {
@@ -119,7 +120,7 @@ WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) no
119120
}
120121

121122
WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept {
122-
return stage2::parse_structurals<true>(*this, _doc);
123+
return stage2::structural_parser<stage2::tape_builder>::parse<true>(*this, _doc);
123124
}
124125

125126
WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept {

src/westmere/dom_parser_implementation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ really_inline simd8<bool> must_be_2_3_continuation(const simd8<uint8_t> prev2, c
8282
#include "westmere/stringparsing.h"
8383
#include "westmere/numberparsing.h"
8484
#include "generic/stage2/structural_parser.h"
85+
#include "generic/stage2/tape_builder.h"
8586

8687
//
8788
// Implementation-specific overrides
@@ -113,7 +114,7 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons
113114
}
114115

115116
WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept {
116-
if (auto error = stage2::parse_structurals<false>(*this, _doc)) { return error; }
117+
if (auto error = stage2::structural_parser<stage2::tape_builder>::parse<false>(*this, _doc)) { return error; }
117118

118119
// If we didn't make it to the end, it's an error
119120
if ( next_structural_index != n_structural_indexes ) {
@@ -125,7 +126,7 @@ WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) no
125126
}
126127

127128
WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept {
128-
return stage2::parse_structurals<true>(*this, _doc);
129+
return stage2::structural_parser<stage2::tape_builder>::parse<true>(*this, _doc);
129130
}
130131

131132
WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept {

0 commit comments

Comments
 (0)