Put parser capacity / max_depth back into parser

This commit is contained in:
John Keiser 2021-02-05 15:16:42 -08:00
parent ea119a5679
commit c7935ceed1
2 changed files with 8 additions and 2 deletions

View File

@ -6,6 +6,8 @@ simdjson_warn_unused simdjson_really_inline error_code parser::allocate(size_t n
if (string_buf && new_capacity == capacity() && new_max_depth == max_depth()) { return SUCCESS; }
// string_capacity copied from document::allocate
_capacity = 0;
_max_depth = 0;
size_t string_capacity = SIMDJSON_ROUNDUP_N(5 * new_capacity / 3 + SIMDJSON_PADDING, 64);
string_buf.reset(new (std::nothrow) uint8_t[string_capacity]);
#if SIMDJSON_API_USAGE_CHECKS
@ -17,6 +19,8 @@ simdjson_warn_unused simdjson_really_inline error_code parser::allocate(size_t n
} else {
SIMDJSON_TRY( simdjson::active_implementation->create_dom_parser_implementation(new_capacity, new_max_depth, implementation) );
}
_capacity = new_capacity;
_max_depth = new_max_depth;
return SUCCESS;
}
@ -50,10 +54,10 @@ simdjson_warn_unused simdjson_really_inline simdjson_result<json_iterator> parse
}
simdjson_really_inline size_t parser::capacity() const noexcept {
return implementation ? implementation->capacity() : 0;
return _capacity;
}
simdjson_really_inline size_t parser::max_depth() const noexcept {
return implementation ? implementation->max_depth() : DEFAULT_MAX_DEPTH;
return implementation ? _max_depth : DEFAULT_MAX_DEPTH;
}

View File

@ -109,6 +109,8 @@ public:
private:
/** @private [for benchmarking access] The implementation to use */
std::unique_ptr<internal::dom_parser_implementation> implementation{};
size_t _capacity{0};
size_t _max_depth{0};
std::unique_ptr<uint8_t[]> string_buf{};
#if SIMDJSON_API_USAGE_CHECKS
std::unique_ptr<token_position[]> start_positions{};