Skip to content

Commit a9a8af6

Browse files
committed
Don't write start object/array until the end
1 parent 71d3746 commit a9a8af6

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/generic/stage2/structural_parser.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,51 +50,51 @@ struct structural_parser {
5050
return doc_parser().doc;
5151
}
5252

53-
WARN_UNUSED really_inline bool start_scope(internal::tape_type type) {
53+
WARN_UNUSED really_inline bool start_scope() {
5454
bool exceeded_max_depth = depth >= doc_parser().max_depth();
5555
if (exceeded_max_depth) { log_error("Exceeded max depth!"); return true; }
56-
write_tape(0, type); // if the document is correct, this gets rewritten later
56+
doc_parser().current_loc++;
5757
return false;
5858
}
5959

6060
WARN_UNUSED really_inline bool start_document() {
6161
log_start_value("document");
62-
return start_scope(internal::tape_type::ROOT);
62+
return start_scope();
6363
}
6464

6565
WARN_UNUSED really_inline bool start_object() {
6666
log_start_value("object");
67-
return start_scope(internal::tape_type::START_OBJECT);
67+
return start_scope();
6868
}
6969

7070
WARN_UNUSED really_inline bool start_array() {
7171
log_start_value("array");
72-
return start_scope(internal::tape_type::START_ARRAY);
72+
return start_scope();
7373
}
7474

7575
// this function is responsible for annotating the start of the scope
76-
really_inline void end_scope(internal::tape_type type, uint32_t start_loc, uint32_t count) noexcept {
76+
really_inline void end_scope(internal::tape_type start, internal::tape_type end, uint32_t start_loc, uint32_t count) noexcept {
7777
// write our doc.tape location to the header scope
7878
// The root scope gets written *at* the previous location.
79-
write_tape(start_loc, type);
79+
write_tape(start_loc, end);
8080
// count can overflow if it exceeds 24 bits... so we saturate
8181
// the convention being that a cnt of 0xffffff or more is undetermined in value (>= 0xffffff).
8282
const uint32_t cntsat = count > 0xFFFFFF ? 0xFFFFFF : count;
8383
// This is a load and an OR. It would be possible to just write once at doc.tape[d.tape_index]
84-
doc().tape[start_loc] |= doc_parser().current_loc | (uint64_t(cntsat) << 32);
84+
doc().tape[start_loc] = doc_parser().current_loc | (uint64_t(cntsat) << 32) | ((uint64_t(char(start))) << 56);
8585
}
8686

8787
really_inline void end_object(uint32_t start_loc, uint32_t count) {
8888
log_end_value("object");
89-
end_scope(internal::tape_type::END_OBJECT, start_loc, count);
89+
end_scope(internal::tape_type::START_OBJECT, internal::tape_type::END_OBJECT, start_loc, count);
9090
}
9191
really_inline void end_array(uint32_t start_loc, uint32_t count) {
9292
log_end_value("array");
93-
end_scope(internal::tape_type::END_ARRAY, start_loc, count);
93+
end_scope(internal::tape_type::START_ARRAY, internal::tape_type::END_ARRAY, start_loc, count);
9494
}
9595
really_inline void end_document(uint32_t start_loc, uint32_t count) {
9696
log_end_value("document");
97-
end_scope(internal::tape_type::ROOT, start_loc, count);
97+
end_scope(internal::tape_type::ROOT, internal::tape_type::ROOT, start_loc, count);
9898
}
9999

100100
really_inline void write_tape(uint64_t val, internal::tape_type t) noexcept {

0 commit comments

Comments
 (0)