8000 Decrement depth in builder · JavaScriptExpert/simdjson@02a6613 · GitHub
[go: up one dir, main page]

Skip to content

Commit 02a6613

Browse files
committed
Decrement depth in builder
1 parent c45bcff commit 02a6613

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/generic/stage2/structural_parser.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ object_continue: {
139139
} // object_continue:
140140

141141
scope_end: {
142-
depth--;
143-
if (depth == 0) { goto document_end; }
144-
if (dom_parser.is_array[depth]) { goto array_continue; }
142+
auto parent = visitor.end_container(*this);
143+
if (!parent.in_container(*this)) { goto document_end; }
144+
if (parent.in_array(*this)) { goto array_continue; }
145145
goto object_continue;
146146
} // scope_end:
147147

src/generic/stage2/tape_builder.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ struct tape_builder {
102102
tape.append(start_tape_index, internal::tape_type::ROOT);
103103
tape_writer::write(iter.dom_parser.doc->tape[start_tape_index], next_tape_index(iter), internal::tape_type::ROOT);
104104
}
105+
// Called after end_object/end_array. Not called after empty_object/empty_array,
106+
// as the parent is already known in those cases.
107+
//
108+
// The object returned from end_container() should support the in_container(),
109+
// in_array() and in_object() methods, allowing the iterator to branch to the
110+
// correct place.
111+
really_inline tape_builder &end_container(structural_parser &iter) {
112+
iter.depth--;
113+
return *this;
114+
}
105115

106116
WARN_UNUSED really_inline error_code parse_key(structural_parser &iter, const uint8_t *value) {
107117
return parse_string(iter, value, true);
@@ -195,6 +205,15 @@ struct tape_builder {
195205
really_inline void increment_count(structural_parser &iter) {
196206
iter.dom_parser.open_containers[iter.depth].count++; // we have a key value pair in the object at parser.dom_parser.depth - 1
197207
}
208+
really_inline bool in_container(structural_parser &iter) {
209+
return iter.depth != 0;
210+
}
211+
really_inline bool in_array(structural_parser &iter) {
212+
return iter.dom_parser.is_array[iter.depth];
213+
}
214+
really_inline bool in_object(structural_parser &iter) {
215+
return !iter.dom_parser.is_array[iter.depth];
216+
}
198217

199218
// private:
200219

0 commit comments

Comments
 (0)
0