Skip to content

Commit e180dc4

Browse files
committed
Move container logging into json_iterator
1 parent 268b884 commit e180dc4

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

src/generic/stage2/json_iterator.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
110110
// Start the document
111111
//
112112
if (at_eof()) { return EMPTY; }
113+
log_start_value("document");
113114
SIMDJSON_TRY( visitor.visit_document_start(*this) );
114115

115116
//
@@ -122,22 +123,14 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
122123
// could get into memory corruption. See https://github.com/simdjson/simdjson/issues/906
123124
if (!STREAMING) {
124125
switch (*value) {
125-
case '{':
126-
if (last_structural() != '}') {
127-
return TAPE_ERROR;
128-
}
129-
break;
130-
case '[':
131-
if (last_structural() != ']') {
132-
return TAPE_ERROR;
133-
}
134-
break;
126+
case '{': if (last_structural() != '}') { return TAPE_ERROR; }; break;
127+
case '[': if (last_structural() != ']') { return TAPE_ERROR; }; break;
135128
}
136129
}
137130

138131
switch (*value) {
139-
case '{': if (*peek() == '}') { advance(); SIMDJSON_TRY( visitor.visit_empty_object(*this) ); break; } goto object_begin;
140-
case '[': if (*peek() == ']') { advance(); SIMDJSON_TRY( visitor.visit_empty_array(*this) ); break; } goto array_begin;
132+
case '{': if (*peek() == '}') { advance(); log_value("empty object"); SIMDJSON_TRY( visitor.visit_empty_object(*this) ); break; } goto object_begin;
133+
case '[': if (*peek() == ']') { advance(); log_value("empty array"); SIMDJSON_TRY( visitor.visit_empty_array(*this) ); break; } goto array_begin;
141134
default: SIMDJSON_TRY( visitor.visit_root_primitive(*this, value) ); break;
142135
}
143136
}
@@ -147,6 +140,7 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
147140
// Object parser states
148141
//
149142
object_begin:
143+
log_start_value("object");
150144
depth++;
151145
if (depth >= dom_parser.max_depth()) { log_error("Exceeded max depth!"); return DEPTH_ERROR; }
152146
SIMDJSON_TRY( visitor.visit_object_start(*this) );
@@ -164,8 +158,8 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
164158
{
165159
auto value = advance();
166160
switch (*value) {
167-
case '{': if (*peek() == '}') { advance(); SIMDJSON_TRY( visitor.visit_empty_object(*this) ); break; } goto object_begin;
168-
case '[': if (*peek() == ']') { advance(); SIMDJSON_TRY( visitor.visit_empty_array(*this) ); break; } goto array_begin;
161+
case '{': if (*peek() == '}') { advance(); log_value("empty object"); SIMDJSON_TRY( visitor.visit_empty_object(*this) ); break; } goto object_begin;
162+
case '[': if (*peek() == ']') { advance(); log_value("empty array"); SIMDJSON_TRY( visitor.visit_empty_array(*this) ); break; } goto array_begin;
169163
default: SIMDJSON_TRY( visitor.visit_primitive(*this, value) ); break;
170164
}
171165
}
@@ -180,7 +174,7 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
180174
SIMDJSON_TRY( visitor.visit_key(*this, key) );
181175
}
182176
goto object_field;
183-
case '}': SIMDJSON_TRY( visitor.visit_object_end(*this) ); goto scope_end;
177+
case '}': log_end_value("object"); SIMDJSON_TRY( visitor.visit_object_end(*this) ); goto scope_end;
184178
default: log_error("No comma between object fields"); return TAPE_ERROR;
185179
}
186180

@@ -194,6 +188,7 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
194188
// Array parser states
195189
//
196190
array_begin:
191+
log_start_value("array");
197192
depth++;
198193
if (depth >= dom_parser.max_depth()) { log_error("Exceeded max depth!"); return DEPTH_ERROR; }
199194
SIMDJSON_TRY( visitor.visit_array_start(*this) );
@@ -204,20 +199,21 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
204199
{
205200
auto value = advance();
206201
switch (*value) {
207-
case '{': if (*peek() == '}') { advance(); SIMDJSON_TRY( visitor.visit_empty_object(*this) ); break; } goto object_begin;
208-
case '[': if (*peek() == ']') { advance(); SIMDJSON_TRY( visitor.visit_empty_array(*this) ); break; } goto array_begin;
202+
case '{': if (*peek() == '}') { advance(); log_value("empty object"); SIMDJSON_TRY( visitor.visit_empty_object(*this) ); break; } goto object_begin;
203+
case '[': if (*peek() == ']') { advance(); log_value("empty array"); SIMDJSON_TRY( visitor.visit_empty_array(*this) ); break; } goto array_begin;
209204
default: SIMDJSON_TRY( visitor.visit_primitive(*this, value) ); break;
210205
}
211206
}
212207

213208
array_continue:
214209
switch (*advance()) {
215210
case ',': SIMDJSON_TRY( visitor.increment_count(*this) ); goto array_value;
216-
case ']': SIMDJSON_TRY( visitor.visit_array_end(*this) ); goto scope_end;
211+
case ']': log_end_value("array"); SIMDJSON_TRY( visitor.visit_array_end(*this) ); goto scope_end;
217212
default: log_error("Missing comma between array values"); return TAPE_ERROR;
218213
}
219214

220215
document_end:
216+
log_end_value("document");
221217
SIMDJSON_TRY( visitor.visit_document_end(*this) );
222218

223219
dom_parser.next_structural_index = uint32_t(next_structural - &dom_parser.structural_indexes[0]);

src/generic/stage2/tape_builder.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,40 +122,32 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_primi
122122
}
123123
}
124124
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_empty_object(json_iterator &iter) noexcept {
125-
iter.log_value("empty object");
126125
return empty_container(iter, internal::tape_type::START_OBJECT, internal::tape_type::END_OBJECT);
127126
}
128127
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_empty_array(json_iterator &iter) noexcept {
129-
iter.log_value("empty array");
130128
return empty_container(iter, internal::tape_type::START_ARRAY, internal::tape_type::END_ARRAY);
131129
}
132130

133131
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_document_start(json_iterator &iter) noexcept {
134-
iter.log_start_value("document");
135132
start_container(iter);
136133
return SUCCESS;
137134
}
138135
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_object_start(json_iterator &iter) noexcept {
139-
iter.log_start_value("object");
140136
start_container(iter);
141137
return SUCCESS;
142138
}
143139
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_array_start(json_iterator &iter) noexcept {
144-
iter.log_start_value("array");
145140
start_container(iter);
146141
return SUCCESS;
147142
}
148143

149144
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_object_end(json_iterator &iter) noexcept {
150-
iter.log_end_value("object");
151145
return end_container(iter, internal::tape_type::START_OBJECT, internal::tape_type::END_OBJECT);
152146
}
153147
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_array_end(json_iterator &iter) noexcept {
154-
iter.log_end_value("array");
155148
return end_container(iter, internal::tape_type::START_ARRAY, internal::tape_type::END_ARRAY);
156149
}
157150
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_document_end(json_iterator &iter) noexcept {
158-
iter.log_end_value("document");
159151
constexpr uint32_t start_tape_index = 0;
160152
tape.append(start_tape_index, internal::tape_type::ROOT);
161153
tape_writer::write(iter.dom_parser.doc->tape[start_tape_index], next_tape_index(iter), internal::tape_type::ROOT);

0 commit comments

Comments
 (0)