Store the pointer to the next structural instead of base

structural_indexes and an index
This commit is contained in:
John Keiser 2020-06-06 12:17:24 -07:00
parent 8793dd3ceb
commit 59d9bc9e48
3 changed files with 11 additions and 16 deletions

View File

@ -62,7 +62,7 @@ namespace logger {
} }
printf("| %c ", printable_char(structurals.at_beginning() ? ' ' : structurals.current_char())); printf("| %c ", printable_char(structurals.at_beginning() ? ' ' : structurals.current_char()));
printf("| %c ", printable_char(structurals.peek_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("| %-*s ", LOG_DETAIL_LEN, detail);
printf("| %*zu ", LOG_INDEX_LEN, structurals.idx); printf("| %*zu ", LOG_INDEX_LEN, structurals.idx);
printf("|\n"); printf("|\n");

View File

@ -3,20 +3,18 @@ namespace stage2 {
class structural_iterator { class structural_iterator {
public: public:
const uint8_t* const buf; const uint8_t* const buf;
const uint32_t* const structural_indexes; uint32_t *next_structural;
size_t next_structural; // next structural index
size_t idx{0}; // location of the structural character in the input (buf) 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 uint8_t c{0}; // used to track the (structural) character we are looking at
dom_parser_implementation &parser; 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}, : buf{_parser.buf},
structural_indexes{_parser.structural_indexes.get()}, next_structural{&_parser.structural_indexes[next_structural_index]},
next_structural{_next_structural},
parser{_parser} { parser{_parser} {
} }
really_inline char advance_char() { really_inline char advance_char() {
idx = structural_indexes[next_structural]; idx = *next_structural;
next_structural++; next_structural++;
c = *current(); c = *current();
return c; return c;
@ -25,7 +23,7 @@ public:
return c; return c;
} }
really_inline char peek_char() { really_inline char peek_char() {
return buf[structural_indexes[next_structural]]; return buf[*next_structural];
} }
really_inline const uint8_t* current() { really_inline const uint8_t* current() {
return &buf[idx]; return &buf[idx];
@ -59,16 +57,13 @@ public:
return result; return result;
} }
really_inline bool past_end(uint32_t n_structural_indexes) { 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) { 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() { really_inline bool at_beginning() {
return next_structural == 0; return next_structural == &parser.structural_indexes[0];
}
really_inline size_t next_structural_index() {
return next_structural;
} }
}; };

View File

@ -268,7 +268,7 @@ struct structural_parser : structural_iterator {
WARN_UNUSED really_inline error_code finish() { WARN_UNUSED really_inline error_code finish() {
end_document(); 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) { if (depth != 0) {
log_error("Unclosed objects or arrays!"); 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 // 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 // into memory corruption. See https://github.com/simdjson/simdjson/issues/906
if (!STREAMING) { 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; goto error;
} }
} }