8000 Make tape_builder primary entry point to stage 2 · JavaScriptExpert/simdjson@04876df · GitHub
[go: up one dir, main page]

Skip to content

Commit 04876df

Browse files
committed
Make tape_builder primary entry point to stage 2
1 parent 700bc52 commit 04876df

File tree

6 files changed

+22
-36
lines changed

6 files changed

+22
-36
lines changed

src/arm64/dom_parser_implementation.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ really_inline simd8<bool> must_be_2_3_continuation(const simd8<uint8_t> prev2, c
111111

112112
#include "arm64/stringparsing.h"
113113
#include "arm64/numberparsing.h"
114-
#include "generic/stage2/structural_parser.h"
115114
#include "generic/stage2/tape_builder.h"
116115

117116
//
@@ -145,15 +144,11 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons
145144
}
146145

147146
WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept {
148-
doc = &_doc;
149-
stage2::tape_builder builder(*doc);
150-
return stage2::structural_parser::parse<false>(*this, builder);
147+
return stage2::tape_builder::parse_document<false>(*this, _doc);
151148
}
152149

153150
WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept {
154-
doc = &_doc;
155-
stage2::tape_builder builder(_doc);
156-
return stage2::structural_parser::parse<true>(*this, builder);
151+
return stage2::tape_builder::parse_document<true>(*this, _doc);
157152
}
158153

159154
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: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,22 +315,17 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons
315315
//
316316
#include "fallback/stringparsing.h"
317317
#include "fallback/numberparsing.h"
318-
#include "generic/stage2/structural_parser.h"
319318
#include "generic/stage2/tape_builder.h"
320319

321320
namespace {
322321
namespace SIMDJSON_IMPLEMENTATION {
323322

324323
WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept {
325-
doc = &_doc;
326-
stage2::tape_builder builder(*doc);
327-
return stage2::structural_parser::parse<false>(*this, builder);
324+
return stage2::tape_builder::parse_document<false>(*this, _doc);
328325
}
329326

330327
WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept {
331-
doc = &_doc;
332-
stage2::tape_builder builder(_doc);
333-
return stage2::structural_parser::parse<true>(*this, builder);
328+
return stage2::tape_builder::parse_document<true>(*this, _doc);
334329
}
335330

336331
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: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ struct structural_parser : structural_iterator {
1717
uint32_t depth{0};
1818

1919
template<bool STREAMING, typename T>
20-
WARN_UNUSED really_inline error_code parse(T &builder) noexcept;
21-
template<bool STREAMING, typename T>
22-
WARN_UNUSED static really_inline error_code parse(dom_parser_implementation &dom_parser, T &builder) noexcept {
23-
structural_parser parser(dom_parser, STREAMING ? dom_parser.next_structural_index : 0);
24-
return parser.parse<STREAMING>(builder);
25-
}
20+
WARN_UNUSED really_inline error_code walk_document(T &builder) noexcept;
2621

2722
// For non-streaming, to pass an explicit 0 as next_structural, which enables optimizations
2823
really_inline structural_parser(dom_parser_implementation &_dom_parser, uint32_t start_structural_index)
@@ -86,7 +81,7 @@ struct structural_parser : structural_iterator {
8681
}; // struct structural_parser
8782

8883
template<bool STREAMING, typename T>
89-
WARN_UNUSED really_inline error_code structural_parser::parse(T &builder) noexcept {
84+
WARN_UNUSED really_inline error_code structural_parser::walk_document(T &builder) noexcept {
9085
logger::log_start();
9186

9287
//

src/generic/stage2/tape_builder.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "generic/stage2/structural_parser.h"
12
#include "generic/stage2/tape_writer.h"
23
#include "generic/stage2/atomparsing.h"
34

@@ -11,11 +12,21 @@ struct tape_builder {
1112
/** Next write location in the string buf for stage 2 parsing */
1213
uint8_t *current_string_buf_loc;
1314

14-
really_inline tape_builder(dom::document &doc) noexcept : tape{doc.tape.get()}, current_string_buf_loc{doc.string_buf.get()} {}
15+
template<bool STREAMING>
16+
WARN_UNUSED static really_inline error_code parse_document(
17+
dom_parser_implementation &dom_parser,
18+
dom::document &doc) noexcept {
19+
dom_parser.doc = &doc;
20+
structural_parser iter(dom_parser, STREAMING ? dom_parser.next_structural_index : 0);
21+
tape_builder builder(doc);
22+
return iter.walk_document<STREAMING>(builder);
23+
}
1524

1625
private:
1726
friend struct structural_parser;
1827

28+
really_inline tape_builder(dom::document &doc) noexcept : tape{doc.tape.get()}, current_string_buf_loc{doc.string_buf.get()} {}
29+
1930
really_inline error_code parse_root_primitive(structural_parser &parser, const uint8_t *value) {
2031
switch (*value) {
2132
case '"': return parse_string(parser, value);

src/haswell/dom_parser_implementation.cpp

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

8281
//
@@ -108,15 +107,11 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons
108107
}
109108

110109
WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept {
111-
doc = &_doc;
112-
stage2::tape_builder builder(_doc);
113-
return stage2::structural_parser::parse<false>(*this, builder);
110+
return stage2::tape_builder::parse_document<false>(*this, _doc);
114111
}
115112

116113
WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept {
117-
doc = &_doc;
118-
stage2::tape_builder builder(_doc);
119-
return stage2::structural_parser::parse<true>(*this, builder);
114+
return stage2::tape_builder::parse_document<true>(*this, _doc);
120115
}
121116

122117
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: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ really_inline simd8<bool> must_be_2_3_continuation(const simd8<uint8_t> prev2, c
8181
//
8282
#include "westmere/stringparsing.h"
8383
#include "westmere/numberparsing.h"
84-
#include "generic/stage2/structural_parser.h"
8584
#include "generic/stage2/tape_builder.h"
8685

8786
//
@@ -114,15 +113,11 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons
114113
}
115114

116115
WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept {
117-
doc = &_doc;
118-
stage2::tape_builder builder(*doc);
119-
return stage2::structural_parser::parse<false>(*this, builder);
116+
return stage2::tape_builder::parse_document<false>(*this, _doc);
120117
}
121118

122119
WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept {
123-
doc = &_doc;
124-
stage2::tape_builder builder(_doc);
125-
return stage2::structural_parser::parse<true>(*this, builder);
120+
return stage2::tape_builder::parse_document<true>(*this, _doc);
126121
}
127122

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

0 commit comments

Comments
 (0)
0