Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ad46154

Browse files
committed
Hardcode document start/end creation
1 parent fa81068 commit ad46154

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

‎src/generic/stage2/structural_parser.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ struct structural_parser : structural_iterator {
3939

4040
WARN_UNUSED really_inline error_code start_document() {
4141
log_start_value("document");
42-
return start_scope(false);
42+
parser.containing_scope[depth].tape_index = next_tape_index();
43+
parser.containing_scope[depth].count = 0;
44+
tape.skip(); // We don't actually *write* the start element until the end.
45+
parser.is_array[depth] = false;
46+
depth++;
47+
if (depth >= parser.max_depth()) { log_error("Exceeded max depth!"); return DEPTH_ERROR; }
48+
return SUCCESS;
4349
}
4450

4551
WARN_UNUSED really_inline error_code start_object(bool parent_is_array) {
@@ -55,15 +61,14 @@ struct structural_parser : structural_iterator {
5561
// this function is responsible for annotating the start of the scope
5662
really_inline void end_scope(internal::tape_type start, internal::tape_type end) noexcept {
5763
depth--;
58-
// write our doc->tape location to the header scope
59-
// The root scope gets written *at* the previous location.
60-
tape.append(parser.containing_scope[depth].tape_index, end);
64+
// Write the ending tape element, pointing at the start location
65+
const uint32_t start_tape_index = parser.containing_scope[depth].tape_index;
66+
tape.append(start_tape_index, end);
67+
// Write the start tape element, pointing at the end location (and including count)
6168
// count can overflow if it exceeds 24 bits... so we saturate
6269
// the convention being that a cnt of 0xffffff or more is undetermined in value (>= 0xffffff).
63-
const uint32_t start_tape_index = parser.containing_scope[depth].tape_index;
6470
const uint32_t count = parser.containing_scope[depth].count;
6571
const uint32_t cntsat = count > 0xFFFFFF ? 0xFFFFFF : count;
66-
// This is a load and an OR. It would be possible to just write once at doc->tape[d.tape_index]
6772
tape_writer::write(parser.doc->tape[start_tape_index], next_tape_index() | (uint64_t(cntsat) << 32), start);
6873
}
6974

@@ -81,7 +86,10 @@ struct structural_parser : structural_iterator {
8186
}
8287
really_inline void end_document() {
8388
log_end_value("document");
84-
end_scope(internal::tape_type::ROOT, internal::tape_type::ROOT);
89+
depth--;
90+
constexpr uint32_t start_tape_index = 0;
91+
tape.append(start_tape_index, internal::tape_type::ROOT);
92+
tape_writer::write(parser.doc->tape[start_tape_index], next_tape_index(), internal::tape_type::ROOT);
8593
}
8694

8795
really_inline void empty_container(internal::tape_type start, internal::tape_type end) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /