Store the pointer to the next structural instead of base
structural_indexes and an index
This commit is contained in:
parent
8793dd3ceb
commit
59d9bc9e48
|
@ -62,7 +62,7 @@ namespace logger {
|
|||
}
|
||||
printf("| %c ", printable_char(structurals.at_beginning() ? ' ' : structurals.current_char()));
|
||||
printf("| %c ", printable_char(structurals.peek_char()));
|
||||
printf("| %5u ", structurals.structural_indexes[structurals.next_structural]);
|
||||
printf("| %5u ", structurals.parser.structural_indexes[*structurals.next_structural]);
|
||||
printf("| %-*s ", LOG_DETAIL_LEN, detail);
|
||||
printf("| %*zu ", LOG_INDEX_LEN, structurals.idx);
|
||||
printf("|\n");
|
||||
|
|
|
@ -3,20 +3,18 @@ namespace stage2 {
|
|||
class structural_iterator {
|
||||
public:
|
||||
const uint8_t* const buf;
|
||||
const uint32_t* const structural_indexes;
|
||||
size_t next_structural; // next structural index
|
||||
uint32_t *next_structural;
|
||||
size_t idx{0}; // location of the structural character in the input (buf)
|
||||
uint8_t c{0}; // used to track the (structural) character we are looking at
|
||||
dom_parser_implementation &parser;
|
||||
|
||||
really_inline structural_iterator(dom_parser_implementation &_parser, size_t _next_structural)
|
||||
really_inline structural_iterator(dom_parser_implementation &_parser, size_t next_structural_index)
|
||||
: buf{_parser.buf},
|
||||
structural_indexes{_parser.structural_indexes.get()},
|
||||
next_structural{_next_structural},
|
||||
next_structural{&_parser.structural_indexes[next_structural_index]},
|
||||
parser{_parser} {
|
||||
}
|
||||
really_inline char advance_char() {
|
||||
idx = structural_indexes[next_structural];
|
||||
idx = *next_structural;
|
||||
next_structural++;
|
||||
c = *current();
|
||||
return c;
|
||||
|
@ -25,7 +23,7 @@ public:
|
|||
return c;
|
||||
}
|
||||
really_inline char peek_char() {
|
||||
return buf[structural_indexes[next_structural]];
|
||||
return buf[*next_structural];
|
||||
}
|
||||
really_inline const uint8_t* current() {
|
||||
return &buf[idx];
|
||||
|
@ -59,16 +57,13 @@ public:
|
|||
return result;
|
||||
}
|
||||
really_inline bool past_end(uint32_t n_structural_indexes) {
|
||||
return next_structural > n_structural_indexes;
|
||||
return next_structural > &parser.structural_indexes[n_structural_indexes];
|
||||
}
|
||||
really_inline bool at_end(uint32_t n_structural_indexes) {
|
||||
return next_structural == n_structural_indexes;
|
||||
return next_structural == &parser.structural_indexes[n_structural_indexes];
|
||||
}
|
||||
really_inline bool at_beginning() {
|
||||
return next_structural == 0;
|
||||
}
|
||||
really_inline size_t next_structural_index() {
|
||||
return next_structural;
|
||||
return next_structural == &parser.structural_indexes[0];
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -268,7 +268,7 @@ struct structural_parser : structural_iterator {
|
|||
|
||||
WARN_UNUSED really_inline error_code finish() {
|
||||
end_document();
|
||||
parser.next_structural_index = uint32_t(next_structural_index());
|
||||
parser.next_structural_index = uint32_t(next_structural - &parser.structural_indexes[0]);
|
||||
|
||||
if (depth != 0) {
|
||||
log_error("Unclosed objects or arrays!");
|
||||
|
@ -388,7 +388,7 @@ WARN_UNUSED static error_code parse_structurals(dom_parser_implementation &dom_p
|
|||
// Make sure the outer array is closed before continuing; otherwise, there are ways we could get
|
||||
// into memory corruption. See https://github.com/simdjson/simdjson/issues/906
|
||||
if (!STREAMING) {
|
||||
if (parser.buf[parser.structural_indexes[dom_parser.n_structural_indexes - 1]] != ']') {
|
||||
if (parser.buf[dom_parser.structural_indexes[dom_parser.n_structural_indexes - 1]] != ']') {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue