From 9d693da8529edac0df5fa2e7f4fce6d05700fe7e Mon Sep 17 00:00:00 2001 From: John Keiser Date: Fri, 5 Feb 2021 17:20:24 -0800 Subject: [PATCH] Only set container depth when a container iteration starts --- include/simdjson/generic/ondemand/json_iterator-inl.h | 11 ++++------- include/simdjson/generic/ondemand/json_iterator.h | 1 + .../simdjson/generic/ondemand/value_iterator-inl.h | 6 ++++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/simdjson/generic/ondemand/json_iterator-inl.h b/include/simdjson/generic/ondemand/json_iterator-inl.h index a42934b6..00db5efa 100644 --- a/include/simdjson/generic/ondemand/json_iterator-inl.h +++ b/include/simdjson/generic/ondemand/json_iterator-inl.h @@ -25,10 +25,6 @@ simdjson_really_inline json_iterator::json_iterator(const uint8_t *buf, ondemand _string_buf_loc{parser->string_buf.get()}, _depth{1} { -#if SIMDJSON_API_USAGE_CHECKS - parser->start_positions[0] = token.index; - parser->start_positions[1] = token.index; -#endif logger::log_headers(); } @@ -159,9 +155,6 @@ simdjson_really_inline void json_iterator::descend_to(depth_t child_depth) noexc SIMDJSON_ASSUME(child_depth >= 1 && child_depth < INT32_MAX); SIMDJSON_ASSUME(_depth == child_depth - 1); _depth = child_depth; -#if SIMDJSON_API_USAGE_CHECKS - parser->start_positions[_depth] = token.index; -#endif } simdjson_really_inline depth_t json_iterator::depth() const noexcept { @@ -196,6 +189,10 @@ simdjson_really_inline void json_iterator::reenter_child(token_position position simdjson_really_inline token_position json_iterator::start_position(depth_t depth) const noexcept { return parser->start_positions[depth]; } +simdjson_really_inline void json_iterator::set_start_position(depth_t depth, token_position position) noexcept { + parser->start_positions[depth] = position; +} + #endif diff --git a/include/simdjson/generic/ondemand/json_iterator.h b/include/simdjson/generic/ondemand/json_iterator.h index a0d67230..ff2dc8ab 100644 --- a/include/simdjson/generic/ondemand/json_iterator.h +++ b/include/simdjson/generic/ondemand/json_iterator.h @@ -183,6 +183,7 @@ public: simdjson_really_inline void reenter_child(token_position position, depth_t child_depth) noexcept; #if SIMDJSON_API_USAGE_CHECKS simdjson_really_inline token_position start_position(depth_t depth) const noexcept; + simdjson_really_inline void set_start_position(depth_t depth, token_position position) noexcept; #endif protected: diff --git a/include/simdjson/generic/ondemand/value_iterator-inl.h b/include/simdjson/generic/ondemand/value_iterator-inl.h index 8f6d262c..61208c9d 100644 --- a/include/simdjson/generic/ondemand/value_iterator-inl.h +++ b/include/simdjson/generic/ondemand/value_iterator-inl.h @@ -25,6 +25,9 @@ simdjson_warn_unused simdjson_really_inline bool value_iterator::started_object( return false; } logger::log_start_value(*_json_iter, "object"); +#if SIMDJSON_API_USAGE_CHECKS + _json_iter->set_start_position(_depth, _start_position); +#endif return true; } @@ -285,6 +288,9 @@ simdjson_warn_unused simdjson_really_inline bool value_iterator::started_array() } logger::log_start_value(*_json_iter, "array"); _json_iter->descend_to(depth()+1); +#if SIMDJSON_API_USAGE_CHECKS + _json_iter->set_start_position(_depth, _start_position); +#endif return true; }