@@ -7,13 +7,6 @@ namespace SIMDJSON_IMPLEMENTATION {
7
7
namespace stage2 {
8
8
9
9
struct tape_builder {
10
- /* * Next location to write to tape */
11
- tape_writer tape;
12
- /* * Next write location in the string buf for stage 2 parsing */
13
- uint8_t *current_string_buf_loc;
14
- /* * Current depth (nested objects and arrays) */
15
- uint32_t depth{0 };
16
-
17
10
template <bool STREAMING>
18
11
WARN_UNUSED static really_inline error_code parse_document (
19
12
dom_parser_implementation &dom_parser,
@@ -24,12 +17,7 @@ struct tape_builder {
24
17
return iter.walk_document <STREAMING>(builder);
25
18
}
26
19
27
- private:
28
- friend struct structural_parser ;
29
-
30
- really_inline tape_builder (dom::document &doc) noexcept : tape{doc.tape .get ()}, current_string_buf_loc{doc.string_buf .get ()} {}
31
-
32
- really_inline error_code parse_root_primitive (structural_parser &iter, const uint8_t *value) {
20
+ really_inline error_code root_primitive (structural_parser &iter, const uint8_t *value) {
33
21
switch (*value) {
34
22
case ' "' : return parse_string (iter, value);
35
23
case ' t' : return parse_root_true_atom (iter, value);
@@ -44,7 +32,7 @@ struct tape_builder {
44
32
return TAPE_ERROR;
45
33
}
46
34
}
47
- really_inline error_code parse_primitive (structural_parser &iter, const uint8_t *value) {
35
+ really_inline error_code primitive (structural_parser &iter, const uint8_t *value) {
48
36
switch (*value) {
49
37
case ' "' : return parse_string (iter, value);
50
38
case ' t' : return parse_true_atom (iter, value);
@@ -110,6 +98,10 @@ struct tape_builder {
110
98
}
111
99
return SUCCESS;
112
100
}
101
+ WARN_UNUSED really_inline error_code key (structural_parser &iter, const uint8_t *value) {
102
+ return parse_string (iter, value, true );
103
+ }
104
+
113
105
// Called after end_object/end_array. Not called after empty_object/empty_array,
114
106
// as the parent is already known in those cases.
115
107
//
@@ -120,10 +112,30 @@ struct tape_builder {
120
112
depth--;
121
113
return *this ;
122
114
}
123
-
124
- WARN_UNUSED really_inline error_code parse_key (structural_parser &iter, const uint8_t *value ) {
125
- return parse_string ( iter, value, true );
115
+ // increment_count increments the count of keys in an object or values in an array.
116
+ really_inline void increment_count (structural_parser &iter) {
117
+ iter. dom_parser . open_containers [depth]. count ++; // we have a key value pair in the object at parser.dom_parser.depth - 1
126
118
}
119
+ really_inline bool in_container (structural_parser &) {
120
+ return depth != 0 ;
121
+ }
122
+ really_inline bool in_array (structural_parser &iter) {
123
+ return iter.dom_parser .is_array [depth];
124
+ }
125
+ really_inline bool in_object (structural_parser &iter) {
126
+ return !iter.dom_parser .is_array [depth];
127
+ }
128
+
129
+ private:
130
+ /* * Next location to write to tape */
131
+ tape_writer tape;
132
+ /* * Next write location in the string buf for stage 2 parsing */
133
+ uint8_t *current_string_buf_loc;
134
+ /* * Current depth (nested objects and arrays) */
135
+ uint32_t depth{0 };
136
+
137
+ really_inline tape_builder (dom::document &doc) noexcept : tape{doc.tape .get ()}, current_string_buf_loc{doc.string_buf .get ()} {}
138
+
127
139
WARN_UNUSED really_inline error_code parse_string (structural_parser &iter, const uint8_t *value, bool key = false ) {
128
140
iter.log_value (key ? " key" : " string" );
129
141
uint8_t *dst = on_start_string (iter);
@@ -209,20 +221,6 @@ struct tape_builder {
209
221
return SUCCESS;
210
222
}
211
223
212
- // increment_count increments the count of keys in an object or values in an array.
213
- really_inline void increment_count (structural_parser &iter) {
214
- iter.dom_parser .open_containers [depth].count ++; // we have a key value pair in the object at parser.dom_parser.depth - 1
215
- }
216
- really_inline bool in_container (structural_parser &) {
217
- return depth != 0 ;
218
- }
219
- really_inline bool in_array (structural_parser &iter) {
220
- return iter.dom_parser .is_array [depth];
221
- }
222
- really_inline bool in_object (structural_parser &iter) {
223
- return !iter.dom_parser .is_array [depth];
224
- }
225
-
226
224
// private:
227
225
228
226
really_inline uint32_t next_tape_index (structural_parser &iter) {
0 commit comments