containing_scope -> open_container
This commit is contained in:
parent
8a8eea53a2
commit
11076bf337
|
@ -4,16 +4,18 @@
|
|||
namespace {
|
||||
namespace SIMDJSON_IMPLEMENTATION {
|
||||
|
||||
// expectation: sizeof(scope_descriptor) = 64/8.
|
||||
struct scope_descriptor {
|
||||
// expectation: sizeof(open_container) = 64/8.
|
||||
struct open_container {
|
||||
uint32_t tape_index; // where, on the tape, does the scope ([,{) begins
|
||||
uint32_t count; // how many elements in the scope
|
||||
}; // struct scope_descriptor
|
||||
}; // struct open_container
|
||||
|
||||
static_assert(sizeof(open_container) == 64/8, "Open container must be 64 bits");
|
||||
|
||||
class dom_parser_implementation final : public internal::dom_parser_implementation {
|
||||
public:
|
||||
/** Tape location of each open { or [ */
|
||||
std::unique_ptr<scope_descriptor[]> containing_scope{};
|
||||
std::unique_ptr<open_container[]> open_containers{};
|
||||
/** Whether each open container is a [ or { */
|
||||
std::unique_ptr<bool[]> is_array{};
|
||||
/** Buffer passed to stage 1 */
|
||||
|
|
|
@ -7,10 +7,10 @@ namespace allocate {
|
|||
// Allocates stage 2 internal state and outputs in the parser
|
||||
//
|
||||
simdjson_really_inline error_code set_max_depth(dom_parser_implementation &parser, size_t max_depth) {
|
||||
parser.containing_scope.reset(new (std::nothrow) scope_descriptor[max_depth]);
|
||||
parser.open_containers.reset(new (std::nothrow) open_container[max_depth]);
|
||||
parser.is_array.reset(new (std::nothrow) bool[max_depth]);
|
||||
|
||||
if (!parser.is_array || !parser.containing_scope) {
|
||||
if (!parser.is_array || !parser.open_containers) {
|
||||
return MEMALLOC;
|
||||
}
|
||||
return SUCCESS;
|
||||
|
|
|
@ -173,7 +173,7 @@ private:
|
|||
|
||||
// increment_count increments the count of keys in an object or values in an array.
|
||||
simdjson_really_inline void increment_count(structural_parser &parser) {
|
||||
parser.dom_parser.containing_scope[parser.depth].count++; // we have a key value pair in the object at parser.dom_parser.depth - 1
|
||||
parser.dom_parser.open_containers[parser.depth].count++; // we have a key value pair in the object at parser.dom_parser.depth - 1
|
||||
}
|
||||
|
||||
// private:
|
||||
|
@ -189,19 +189,19 @@ private:
|
|||
}
|
||||
|
||||
simdjson_really_inline void start_container(structural_parser &parser) {
|
||||
parser.dom_parser.containing_scope[parser.depth].tape_index = next_tape_index(parser);
|
||||
parser.dom_parser.containing_scope[parser.depth].count = 0;
|
||||
parser.dom_parser.open_containers[parser.depth].tape_index = next_tape_index(parser);
|
||||
parser.dom_parser.open_containers[parser.depth].count = 0;
|
||||
tape.skip(); // We don't actually *write* the start element until the end.
|
||||
}
|
||||
|
||||
simdjson_really_inline void end_container(structural_parser &parser, internal::tape_type start, internal::tape_type end) noexcept {
|
||||
// Write the ending tape element, pointing at the start location
|
||||
const uint32_t start_tape_index = parser.dom_parser.containing_scope[parser.depth].tape_index;
|
||||
const uint32_t start_tape_index = parser.dom_parser.open_containers[parser.depth].tape_index;
|
||||
tape.append(start_tape_index, end);
|
||||
// Write the start tape element, pointing at the end location (and including count)
|
||||
// count can overflow if it exceeds 24 bits... so we saturate
|
||||
// the convention being that a cnt of 0xffffff or more is undetermined in value (>= 0xffffff).
|
||||
const uint32_t count = parser.dom_parser.containing_scope[parser.depth].count;
|
||||
const uint32_t count = parser.dom_parser.open_containers[parser.depth].count;
|
||||
const uint32_t cntsat = count > 0xFFFFFF ? 0xFFFFFF : count;
|
||||
tape_writer::write(parser.dom_parser.doc->tape[start_tape_index], next_tape_index(parser) | (uint64_t(cntsat) << 32), start);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue