Stop caching current structural, keep current index around instead of
next
This commit is contained in:
parent
5f00b37e21
commit
d178e089a6
|
@ -62,9 +62,9 @@ namespace logger {
|
|||
}
|
||||
printf("| %c ", printable_char(structurals.at_beginning() ? ' ' : structurals.current_char()));
|
||||
printf("| %c ", printable_char(structurals.peek_char()));
|
||||
printf("| %5u ", structurals.parser.structural_indexes[*structurals.next_structural]);
|
||||
printf("| %5u ", structurals.parser.structural_indexes[*(structurals.current_structural+1)]);
|
||||
printf("| %-*s ", LOG_DETAIL_LEN, detail);
|
||||
printf("| %*u ", LOG_INDEX_LEN, *(structurals.next_structural-1));
|
||||
printf("| %*u ", LOG_INDEX_LEN, *structurals.current_structural);
|
||||
printf("|\n");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,34 +3,33 @@ namespace stage2 {
|
|||
class structural_iterator {
|
||||
public:
|
||||
const uint8_t* const buf;
|
||||
uint32_t *next_structural;
|
||||
uint8_t c{0}; // used to track the (structural) character we are looking at
|
||||
uint32_t *current_structural;
|
||||
dom_parser_implementation &parser;
|
||||
|
||||
really_inline structural_iterator(dom_parser_implementation &_parser, size_t next_structural_index)
|
||||
// Start a structural
|
||||
really_inline structural_iterator(dom_parser_implementation &_parser, size_t start_structural_index)
|
||||
: buf{_parser.buf},
|
||||
next_structural{&_parser.structural_indexes[next_structural_index]},
|
||||
current_structural{&_parser.structural_indexes[start_structural_index]},
|
||||
parser{_parser} {
|
||||
}
|
||||
really_inline char advance_char() {
|
||||
c = buf[*next_structural];
|
||||
next_structural++;
|
||||
return c;
|
||||
}
|
||||
really_inline char current_char() {
|
||||
return c;
|
||||
}
|
||||
really_inline char peek_char() {
|
||||
return buf[*next_structural];
|
||||
}
|
||||
// Get the buffer position of the current structural character
|
||||
really_inline const uint8_t* current() {
|
||||
return &buf[current_structural_index()];
|
||||
return &buf[*current_structural];
|
||||
}
|
||||
// Get the current structural character
|
||||
really_inline char current_char() {
|
||||
return buf[*current_structural];
|
||||
}
|
||||
// Get the next structural character without advancing
|
||||
really_inline char peek_char() {
|
||||
return buf[*(current_structural+1)];
|
||||
}
|
||||
really_inline char advance_char() {
|
||||
current_structural++;
|
||||
return buf[*current_structural];
|
||||
}
|
||||
really_inline size_t remaining_len() {
|
||||
return parser.len - current_structural_index();
|
||||
}
|
||||
really_inline uint32_t current_structural_index() {
|
||||
return *(next_structural-1);
|
||||
return parser.len - *current_structural;
|
||||
}
|
||||
template<typename F>
|
||||
really_inline bool with_space_terminated_copy(const F& f) {
|
||||
|
@ -53,18 +52,18 @@ public:
|
|||
}
|
||||
memcpy(copy, buf, parser.len);
|
||||
memset(copy + parser.len, ' ', SIMDJSON_PADDING);
|
||||
bool result = f(reinterpret_cast<const uint8_t*>(copy), current_structural_index());
|
||||
bool result = f(reinterpret_cast<const uint8_t*>(copy), *current_structural);
|
||||
free(copy);
|
||||
return result;
|
||||
}
|
||||
really_inline bool past_end(uint32_t n_structural_indexes) {
|
||||
return next_structural > &parser.structural_indexes[n_structural_indexes];
|
||||
return current_structural >= &parser.structural_indexes[n_structural_indexes];
|
||||
}
|
||||
really_inline bool at_end(uint32_t n_structural_indexes) {
|
||||
return next_structural == &parser.structural_indexes[n_structural_indexes];
|
||||
return current_structural == &parser.structural_indexes[n_structural_indexes];
|
||||
}
|
||||
really_inline bool at_beginning() {
|
||||
return next_structural == &parser.structural_indexes[0];
|
||||
return current_structural == parser.structural_indexes.get();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -72,11 +72,12 @@ struct number_writer {
|
|||
struct structural_parser : structural_iterator {
|
||||
/** Next write location in the string buf for stage 2 parsing */
|
||||
uint8_t *current_string_buf_loc{};
|
||||
/** Current depth (nested objects and arrays) */
|
||||
uint32_t depth;
|
||||
|
||||
// For non-streaming, to pass an explicit 0 as next_structural, which enables optimizations
|
||||
really_inline structural_parser(dom_parser_implementation &_parser, uint32_t _next_structural)
|
||||
: structural_iterator(_parser, _next_structural),
|
||||
really_inline structural_parser(dom_parser_implementation &_parser, uint32_t start_structural_index)
|
||||
: structural_iterator(_parser, start_structural_index),
|
||||
depth{0} {
|
||||
}
|
||||
|
||||
|
@ -232,7 +233,7 @@ struct structural_parser : structural_iterator {
|
|||
|
||||
WARN_UNUSED really_inline error_code finish() {
|
||||
end_document();
|
||||
parser.next_structural_index = uint32_t(next_structural - &parser.structural_indexes[0]);
|
||||
parser.next_structural_index = uint32_t(current_structural + 1 - &parser.structural_indexes[0]);
|
||||
|
||||
if (depth != 0) {
|
||||
log_error("Unclosed objects or arrays!");
|
||||
|
@ -283,6 +284,7 @@ struct structural_parser : structural_iterator {
|
|||
}
|
||||
|
||||
really_inline void init() {
|
||||
log_start();
|
||||
current_string_buf_loc = parser.doc->string_buf.get();
|
||||
parser.current_loc = 0;
|
||||
parser.error = UNINITIALIZED;
|
||||
|
@ -294,10 +296,7 @@ struct structural_parser : structural_iterator {
|
|||
return parser.error = EMPTY;
|
||||
}
|
||||
|
||||
log_start();
|
||||
init();
|
||||
// Advance to the first character as soon as possible
|
||||
advance_char();
|
||||
// Push the root scope (there is always at least one scope)
|
||||
if (start_document(finish_state)) {
|
||||
return parser.error = DEPTH_ERROR;
|
||||
|
|
Loading…
Reference in New Issue