@@ -10,6 +10,7 @@ class json_iterator {
10
10
uint32_t *next_structural;
11
11
dom_parser_implementation &dom_parser;
12
12
uint32_t depth{0 };
13
+ const uint8_t *value{}; // Used to keep a value around between states
13
14
14
15
template <bool STREAMING, typename T>
15
16
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code walk_document (T &visitor) noexcept ;
@@ -25,11 +26,9 @@ class json_iterator {
25
26
simdjson_really_inline char peek_next_char () {
26
27
return buf[*(next_structural)];
27
28
}
28
- simdjson_really_inline const uint8_t * advance () {
29
- return &buf[*(next_structural++)];
30
- }
31
- simdjson_really_inline char advance_char () {
32
- return buf[*(next_structural++)];
29
+ simdjson_really_inline char advance () {
30
+ value = &buf[*(next_structural++)];
31
+ return *value;
33
32
}
34
33
simdjson_really_inline size_t remaining_len () {
35
34
return dom_parser.len - *(next_structural-1 );
@@ -45,7 +44,7 @@ class json_iterator {
45
44
template <typename T>
46
45
SIMDJSON_WARN_UNUSED simdjson_really_inline bool empty_object (T &visitor) {
47
46
if (peek_next_char () == ' }' ) {
48
- advance_char ();
47
+ advance ();
49
48
visitor.empty_object (*this );
50
49
return true ;
51
50
}
@@ -54,7 +53,7 @@ class json_iterator {
54
53
template <typename T>
55
54
SIMDJSON_WARN_UNUSED simdjson_really_inline bool empty_array (T &visitor) {
56
55
if (peek_next_char () == ' ]' ) {
57
- advance_char ();
56
+ advance ();
58
57
visitor.empty_array (*this );
59
58
return true ;
60
59
}
@@ -86,8 +85,6 @@ class json_iterator {
86
85
87
86
template <bool STREAMING, typename T>
88
87
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_document (T &visitor) noexcept {
89
- const uint8_t *value; // Used to keep a value around between states
90
-
91
88
logger::log_start ();
92
89
93
90
//
@@ -99,7 +96,7 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
99
96
//
100
97
// Read first value
101
98
//
102
- value = advance ();
99
+ advance ();
103
100
104
101
// Make sure the outer hash or array is closed before continuing; otherwise, there are ways we
105
102
// could get into memory corruption. See https://github.com/simdjson/simdjson/issues/906
@@ -132,35 +129,28 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
132
129
if (depth >= dom_parser.max_depth ()) { log_error (" Exceeded max depth!" ); return DEPTH_ERROR; }
133
130
visitor.start_object (*this );
134
131
135
- value = advance ();
136
- if (*value != ' "' ) { log_error (" Object does not start with a key" ); return TAPE_ERROR; }
132
+ if (advance () != ' "' ) { log_error (" Object does not start with a key" ); return TAPE_ERROR; }
137
133
visitor.increment_count (*this );
138
134
SIMDJSON_TRY ( visitor.key (*this , value) );
139
135
goto object_field;
140
136
141
137
object_field:
142
- if (simdjson_unlikely ( advance_char () != ' :' )) { log_error (" Missing colon after key in object" ); return TAPE_ERROR; }
143
- switch (*(value = advance () )) {
138
+ if (simdjson_unlikely ( advance () != ' :' )) { log_error (" Missing colon after key in object" ); return TAPE_ERROR; }
139
+ switch (advance ()) {
144
140
case ' {' : if (!empty_object (visitor)) { goto object_begin; }; goto object_continue;
145
141
case ' [' : if (!empty_array (visitor)) { goto array_begin; }; goto object_continue;
146
142
default : SIMDJSON_TRY ( visitor.primitive (*this , value) );
147
143
}
148
144
149
145
object_continue:
150
- switch (advance_char ()) {
151
- case ' ,' : {
152
- visitor.increment_count (*this );
153
- value = advance ();
154
- if (simdjson_unlikely ( *value != ' "' )) { log_error (" Key string missing at beginning of field in object" ); return TAPE_ERROR; }
155
- SIMDJSON_TRY ( visitor.key (*this , value) );
156
- goto object_field;
157
- }
158
- case ' }' :
159
- visitor.end_object (*this );
160
- goto scope_end;
161
- default :
162
- log_error (" No comma between object fields" );
163
- return TAPE_ERROR;
146
+ switch (advance ()) {
147
+ case ' ,' :
148
+ visitor.increment_count (*this );
149
+ if (simdjson_unlikely ( advance () != ' "' )) { log_error (" Key string missing at beginning of field in object" ); return TAPE_ERROR; }
150
+ SIMDJSON_TRY ( visitor.key (*this , value) );
151
+ goto object_field;
152
+ case ' }' : visitor.end_object (*this ); goto scope_end;
153
+ default : log_error (" No comma between object fields" ); return TAPE_ERROR;
164
154
}
165
155
166
156
scope_end:
@@ -179,14 +169,14 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
179
169
visitor.increment_count (*this );
180
170
181
171
array_value:
182
- switch (*(value = advance () )) {
172
+ switch (advance ()) {
183
173
case ' {' : if (!empty_object (visitor)) { goto object_begin; }; goto array_continue;
184
174
case ' [' : if (!empty_array (visitor)) { goto array_begin; }; goto array_continue;
185
175
default : SIMDJSON_TRY ( visitor.primitive (*this , value) );
186
176
}
187
177
188
178
array_continue:
189
- switch (advance_char ()) {
179
+ switch (advance ()) {
190
180
case ' ,' : visitor.increment_count (*this ); goto array_value;
191
181
case ' ]' : visitor.end_array (*this ); goto scope_end;
192
182
default : log_error (" Missing comma between array values" ); return TAPE_ERROR;
0 commit comments