diff --git a/include/simdjson/generic/ondemand/array-inl.h b/include/simdjson/generic/ondemand/array-inl.h index 3cd2fb87..f366e3bd 100644 --- a/include/simdjson/generic/ondemand/array-inl.h +++ b/include/simdjson/generic/ondemand/array-inl.h @@ -50,11 +50,6 @@ simdjson_really_inline simdjson_result array::start(value_iterator &iter) SIMDJSON_TRY( iter.start_array().get(has_value) ); return array(iter); } -simdjson_really_inline simdjson_result array::try_start(value_iterator &iter) noexcept { - simdjson_unused bool has_value; - SIMDJSON_TRY( iter.try_start_array().get(has_value) ); - return array(iter); -} simdjson_really_inline array array::started(value_iterator &iter) noexcept { simdjson_unused bool has_value = iter.started_array(); return array(iter); diff --git a/include/simdjson/generic/ondemand/array.h b/include/simdjson/generic/ondemand/array.h index 739ebf9a..60f39852 100644 --- a/include/simdjson/generic/ondemand/array.h +++ b/include/simdjson/generic/ondemand/array.h @@ -41,14 +41,6 @@ protected: * @error INCORRECT_TYPE if the iterator is not at [. */ static simdjson_really_inline simdjson_result start(value_iterator &iter) noexcept; - /** - * Begin array iteration. - * - * @param iter The iterator. Must be where the initial [ is expected. Will be *moved* into the - * resulting array. - * @error INCORRECT_TYPE if the iterator is not at [. - */ - static simdjson_really_inline simdjson_result try_start(value_iterator &iter) noexcept; /** * Begin array iteration. * diff --git a/include/simdjson/generic/ondemand/logger-inl.h b/include/simdjson/generic/ondemand/logger-inl.h index a7107d76..5466e15a 100644 --- a/include/simdjson/generic/ondemand/logger-inl.h +++ b/include/simdjson/generic/ondemand/logger-inl.h @@ -21,20 +21,28 @@ static simdjson_really_inline char printable_char(char c) { simdjson_really_inline void log_event(const json_iterator &iter, const char *type, std::string_view detail, int delta, int depth_delta) noexcept { log_line(iter, "", type, detail, delta, depth_delta); } -simdjson_really_inline void log_value(const json_iterator &iter, const char *type, std::string_view detail, int delta, int depth_delta) noexcept { - log_line(iter, "", type, detail, delta, depth_delta); -} + simdjson_really_inline void log_value(const json_iterator &iter, token_position index, depth_t depth, const char *type, std::string_view detail) noexcept { log_line(iter, index, depth, "", type, detail); } +simdjson_really_inline void log_value(const json_iterator &iter, const char *type, std::string_view detail, int delta, int depth_delta) noexcept { + log_line(iter, "", type, detail, delta, depth_delta); +} + +simdjson_really_inline void log_start_value(const json_iterator &iter, token_position index, depth_t depth, const char *type, std::string_view detail) noexcept { + log_line(iter, index, depth, "+", type, detail); + if (LOG_ENABLED) { log_depth++; } +} simdjson_really_inline void log_start_value(const json_iterator &iter, const char *type, int delta, int depth_delta) noexcept { log_line(iter, "+", type, "", delta, depth_delta); - log_depth++; + if (LOG_ENABLED) { log_depth++; } } + simdjson_really_inline void log_end_value(const json_iterator &iter, const char *type, int delta, int depth_delta) noexcept { - log_depth--; + if (LOG_ENABLED) { log_depth--; } log_line(iter, "-", type, "", delta, depth_delta); } + simdjson_really_inline void log_error(const json_iterator &iter, const char *error, const char *detail, int delta, int depth_delta) noexcept { log_line(iter, "ERROR: ", error, detail, delta, depth_delta); } @@ -45,22 +53,26 @@ simdjson_really_inline void log_error(const json_iterator &iter, token_position simdjson_really_inline void log_event(const value_iterator &iter, const char *type, std::string_view detail, int delta, int depth_delta) noexcept { log_event(iter.json_iter(), type, detail, delta, depth_delta); } + simdjson_really_inline void log_value(const value_iterator &iter, const char *type, std::string_view detail, int delta, int depth_delta) noexcept { log_value(iter.json_iter(), type, detail, delta, depth_delta); } + simdjson_really_inline void log_start_value(const value_iterator &iter, const char *type, int delta, int depth_delta) noexcept { log_start_value(iter.json_iter(), type, delta, depth_delta); } + simdjson_really_inline void log_end_value(const value_iterator &iter, const char *type, int delta, int depth_delta) noexcept { log_end_value(iter.json_iter(), type, delta, depth_delta); } + simdjson_really_inline void log_error(const value_iterator &iter, const char *error, const char *detail, int delta, int depth_delta) noexcept { log_error(iter.json_iter(), error, detail, delta, depth_delta); } simdjson_really_inline void log_headers() noexcept { - log_depth = 0; if (LOG_ENABLED) { + log_depth = 0; printf("\n"); printf("| %-*s ", LOG_EVENT_LEN, "Event"); printf("| %-*s ", LOG_BUFFER_LEN, "Buffer"); diff --git a/include/simdjson/generic/ondemand/logger.h b/include/simdjson/generic/ondemand/logger.h index 4d657df3..8cb0cb77 100644 --- a/include/simdjson/generic/ondemand/logger.h +++ b/include/simdjson/generic/ondemand/logger.h @@ -14,15 +14,16 @@ namespace logger { #endif static simdjson_really_inline void log_headers() noexcept; -static simdjson_really_inline void log_line(const json_iterator &iter, const char *title_prefix, const char *title, std::string_view detail, int delta, int depth_delta) noexcept; static simdjson_really_inline void log_line(const json_iterator &iter, token_position index, depth_t depth, const char *title_prefix, const char *title, std::string_view detail) noexcept; +static simdjson_really_inline void log_line(const json_iterator &iter, const char *title_prefix, const char *title, std::string_view detail, int delta, int depth_delta) noexcept; static simdjson_really_inline void log_event(const json_iterator &iter, const char *type, std::string_view detail="", int delta=0, int depth_delta=0) noexcept; -static simdjson_really_inline void log_value(const json_iterator &iter, const char *type, std::string_view detail="", int delta=-1, int depth_delta=0) noexcept; static simdjson_really_inline void log_value(const json_iterator &iter, token_position index, depth_t depth, const char *type, std::string_view detail="") noexcept; +static simdjson_really_inline void log_value(const json_iterator &iter, const char *type, std::string_view detail="", int delta=-1, int depth_delta=0) noexcept; +static simdjson_really_inline void log_start_value(const json_iterator &iter, token_position index, depth_t depth, const char *type, std::string_view detail="") noexcept; static simdjson_really_inline void log_start_value(const json_iterator &iter, const char *type, int delta=-1, int depth_delta=0) noexcept; static simdjson_really_inline void log_end_value(const json_iterator &iter, const char *type, int delta=-1, int depth_delta=0) noexcept; -static simdjson_really_inline void log_error(const json_iterator &iter, const char *error, const char *detail="", int delta=-1, int depth_delta=0) noexcept; static simdjson_really_inline void log_error(const json_iterator &iter, token_position index, depth_t depth, const char *error, const char *detail="") noexcept; +static simdjson_really_inline void log_error(const json_iterator &iter, const char *error, const char *detail="", int delta=-1, int depth_delta=0) noexcept; static simdjson_really_inline void log_event(const value_iterator &iter, const char *type, std::string_view detail="", int delta=0, int depth_delta=0) noexcept; static simdjson_really_inline void log_value(const value_iterator &iter, const char *type, std::string_view detail="", int delta=-1, int depth_delta=0) noexcept; diff --git a/include/simdjson/generic/ondemand/object-inl.h b/include/simdjson/generic/ondemand/object-inl.h index 83203001..8e5785ba 100644 --- a/include/simdjson/generic/ondemand/object-inl.h +++ b/include/simdjson/generic/ondemand/object-inl.h @@ -38,11 +38,6 @@ simdjson_really_inline simdjson_result object::start(value_iterator &ite SIMDJSON_TRY( iter.start_object().get(has_value) ); return object(iter); } -simdjson_really_inline simdjson_result object::try_start(value_iterator &iter) noexcept { - simdjson_unused bool has_value; - SIMDJSON_TRY( iter.try_start_object().get(has_value) ); - return object(iter); -} simdjson_really_inline object object::started(value_iterator &iter) noexcept { simdjson_unused bool has_value = iter.started_object(); return iter; diff --git a/include/simdjson/generic/ondemand/object.h b/include/simdjson/generic/ondemand/object.h index f484b21b..f4a57db3 100644 --- a/include/simdjson/generic/ondemand/object.h +++ b/include/simdjson/generic/ondemand/object.h @@ -72,7 +72,6 @@ public: protected: static simdjson_really_inline simdjson_result start(value_iterator &iter) noexcept; - static simdjson_really_inline simdjson_result try_start(value_iterator &iter) noexcept; static simdjson_really_inline object started(value_iterator &iter) noexcept; static simdjson_really_inline object resume(const value_iterator &iter) noexcept; simdjson_really_inline object(const value_iterator &iter) noexcept; diff --git a/include/simdjson/generic/ondemand/value-inl.h b/include/simdjson/generic/ondemand/value-inl.h index af2cfcc0..df5a5d12 100644 --- a/include/simdjson/generic/ondemand/value-inl.h +++ b/include/simdjson/generic/ondemand/value-inl.h @@ -13,26 +13,13 @@ simdjson_really_inline value value::resume(const value_iterator &iter) noexcept return iter; } -simdjson_really_inline simdjson_result value::get_array() && noexcept { +simdjson_really_inline simdjson_result value::get_array() noexcept { return array::start(iter); } -simdjson_really_inline simdjson_result value::get_array() & noexcept { - return array::try_start(iter); -} -simdjson_really_inline simdjson_result value::get_object() && noexcept { +simdjson_really_inline simdjson_result value::get_object() noexcept { return object::start(iter); } -simdjson_really_inline simdjson_result value::get_object() & noexcept { - return object::try_start(iter); -} -simdjson_really_inline simdjson_result value::start_or_resume_object() & noexcept { - if (iter.at_start()) { - return get_object(); - } else { - return object::resume(iter); - } -} -simdjson_really_inline simdjson_result value::start_or_resume_object() && noexcept { +simdjson_really_inline simdjson_result value::start_or_resume_object() noexcept { if (iter.at_start()) { return get_object(); } else { @@ -62,44 +49,25 @@ simdjson_really_inline bool value::is_null() noexcept { return iter.is_null(); } -template<> simdjson_really_inline simdjson_result value::get() & noexcept { return get_array(); } -template<> simdjson_really_inline simdjson_result value::get() & noexcept { return get_object(); } -template<> simdjson_really_inline simdjson_result value::get() & noexcept { return get_raw_json_string(); } -template<> simdjson_really_inline simdjson_result value::get() & noexcept { return get_string(); } -template<> simdjson_really_inline simdjson_result value::get() & noexcept { return get_double(); } -template<> simdjson_really_inline simdjson_result value::get() & noexcept { return get_uint64(); } -template<> simdjson_really_inline simdjson_result value::get() & noexcept { return get_int64(); } -template<> simdjson_really_inline simdjson_result value::get() & noexcept { return get_bool(); } +template<> simdjson_really_inline simdjson_result value::get() noexcept { return get_array(); } +template<> simdjson_really_inline simdjson_result value::get() noexcept { return get_object(); } +template<> simdjson_really_inline simdjson_result value::get() noexcept { return get_raw_json_string(); } +template<> simdjson_really_inline simdjson_result value::get() noexcept { return get_string(); } +template<> simdjson_really_inline simdjson_result value::get() noexcept { return get_double(); } +template<> simdjson_really_inline simdjson_result value::get() noexcept { return get_uint64(); } +template<> simdjson_really_inline simdjson_result value::get() noexcept { return get_int64(); } +template<> simdjson_really_inline simdjson_result value::get() noexcept { return get_bool(); } -template<> simdjson_really_inline simdjson_result value::get() && noexcept { return std::forward(*this); } -template<> simdjson_really_inline simdjson_result value::get() && noexcept { return std::forward(*this).get_array(); } -template<> simdjson_really_inline simdjson_result value::get() && noexcept { return std::forward(*this).get_object(); } -template<> simdjson_really_inline simdjson_result value::get() && noexcept { return std::forward(*this).get_raw_json_string(); } -template<> simdjson_really_inline simdjson_result value::get() && noexcept { return std::forward(*this).get_string(); } -template<> simdjson_really_inline simdjson_result value::get() && noexcept { return std::forward(*this).get_double(); } -template<> simdjson_really_inline simdjson_result value::get() && noexcept { return std::forward(*this).get_uint64(); } -template<> simdjson_really_inline simdjson_result value::get() && noexcept { return std::forward(*this).get_int64(); } -template<> simdjson_really_inline simdjson_result value::get() && noexcept { return std::forward(*this).get_bool(); } - -template simdjson_really_inline error_code value::get(T &out) & noexcept { +template simdjson_really_inline error_code value::get(T &out) noexcept { return get().get(out); } -template simdjson_really_inline error_code value::get(T &out) && noexcept { - return std::forward(*this).get().get(out); -} #if SIMDJSON_EXCEPTIONS -simdjson_really_inline value::operator array() && noexcept(false) { - return std::forward(*this).get_array(); +simdjson_really_inline value::operator array() noexcept(false) { + return get_array(); } -simdjson_really_inline value::operator array() & noexcept(false) { - return std::forward(*this).get_array(); -} -simdjson_really_inline value::operator object() && noexcept(false) { - return std::forward(*this).get_object(); -} -simdjson_really_inline value::operator object() & noexcept(false) { - return std::forward(*this).get_object(); +simdjson_really_inline value::operator object() noexcept(false) { + return get_object(); } simdjson_really_inline value::operator uint64_t() noexcept(false) { return get_uint64(); @@ -128,44 +96,26 @@ simdjson_really_inline simdjson_result value::end() & noexcept { return {}; } -simdjson_really_inline simdjson_result value::find_field(std::string_view key) & noexcept { +simdjson_really_inline simdjson_result value::find_field(std::string_view key) noexcept { return start_or_resume_object().find_field(key); } -simdjson_really_inline simdjson_result value::find_field(std::string_view key) && noexcept { - return std::forward(*this).start_or_resume_object().find_field(key); -} -simdjson_really_inline simdjson_result value::find_field(const char *key) & noexcept { +simdjson_really_inline simdjson_result value::find_field(const char *key) noexcept { return start_or_resume_object().find_field(key); } -simdjson_really_inline simdjson_result value::find_field(const char *key) && noexcept { - return std::forward(*this).start_or_resume_object().find_field(key); -} -simdjson_really_inline simdjson_result value::find_field_unordered(std::string_view key) & noexcept { +simdjson_really_inline simdjson_result value::find_field_unordered(std::string_view key) noexcept { return start_or_resume_object().find_field_unordered(key); } -simdjson_really_inline simdjson_result value::find_field_unordered(std::string_view key) && noexcept { - return std::forward(*this).start_or_resume_object().find_field_unordered(key); -} -simdjson_really_inline simdjson_result value::find_field_unordered(const char *key) & noexcept { +simdjson_really_inline simdjson_result value::find_field_unordered(const char *key) noexcept { return start_or_resume_object().find_field_unordered(key); } -simdjson_really_inline simdjson_result value::find_field_unordered(const char *key) && noexcept { - return std::forward(*this).start_or_resume_object().find_field_unordered(key); -} -simdjson_really_inline simdjson_result value::operator[](std::string_view key) & noexcept { +simdjson_really_inline simdjson_result value::operator[](std::string_view key) noexcept { return start_or_resume_object()[key]; } -simdjson_really_inline simdjson_result value::operator[](std::string_view key) && noexcept { - return std::forward(*this).start_or_resume_object()[key]; -} -simdjson_really_inline simdjson_result value::operator[](const char *key) & noexcept { +simdjson_really_inline simdjson_result value::operator[](const char *key) noexcept { return start_or_resume_object()[key]; } -simdjson_really_inline simdjson_result value::operator[](const char *key) && noexcept { - return std::forward(*this).start_or_resume_object()[key]; -} } // namespace ondemand } // namespace SIMDJSON_IMPLEMENTATION @@ -197,73 +147,41 @@ simdjson_really_inline simdjson_result simdjson_result::find_field(std::string_view key) & noexcept { +simdjson_really_inline simdjson_result simdjson_result::find_field(std::string_view key) noexcept { if (error()) { return error(); } return first.find_field(key); } -simdjson_really_inline simdjson_result simdjson_result::find_field(std::string_view key) && noexcept { - if (error()) { return error(); } - return std::forward(first).find_field(key); -} -simdjson_really_inline simdjson_result simdjson_result::find_field(const char *key) & noexcept { +simdjson_really_inline simdjson_result simdjson_result::find_field(const char *key) noexcept { if (error()) { return error(); } return first.find_field(key); } -simdjson_really_inline simdjson_result simdjson_result::find_field(const char *key) && noexcept { - if (error()) { return error(); } - return std::forward(first).find_field(key); -} -simdjson_really_inline simdjson_result simdjson_result::find_field_unordered(std::string_view key) & noexcept { +simdjson_really_inline simdjson_result simdjson_result::find_field_unordered(std::string_view key) noexcept { if (error()) { return error(); } return first.find_field_unordered(key); } -simdjson_really_inline simdjson_result simdjson_result::find_field_unordered(std::string_view key) && noexcept { - if (error()) { return error(); } - return std::forward(first).find_field_unordered(key); -} -simdjson_really_inline simdjson_result simdjson_result::find_field_unordered(const char *key) & noexcept { +simdjson_really_inline simdjson_result simdjson_result::find_field_unordered(const char *key) noexcept { if (error()) { return error(); } return first.find_field_unordered(key); } -simdjson_really_inline simdjson_result simdjson_result::find_field_unordered(const char *key) && noexcept { - if (error()) { return error(); } - return std::forward(first).find_field_unordered(key); -} -simdjson_really_inline simdjson_result simdjson_result::operator[](std::string_view key) & noexcept { +simdjson_really_inline simdjson_result simdjson_result::operator[](std::string_view key) noexcept { if (error()) { return error(); } return first[key]; } -simdjson_really_inline simdjson_result simdjson_result::operator[](std::string_view key) && noexcept { - if (error()) { return error(); } - return std::forward(first)[key]; -} -simdjson_really_inline simdjson_result simdjson_result::operator[](const char *key) & noexcept { +simdjson_really_inline simdjson_result simdjson_result::operator[](const char *key) noexcept { if (error()) { return error(); } return first[key]; } -simdjson_really_inline simdjson_result simdjson_result::operator[](const char *key) && noexcept { - if (error()) { return error(); } - return std::forward(first)[key]; -} -simdjson_really_inline simdjson_result simdjson_result::get_array() & noexcept { +simdjson_really_inline simdjson_result simdjson_result::get_array() noexcept { if (error()) { return error(); } return first.get_array(); } -simdjson_really_inline simdjson_result simdjson_result::get_array() && noexcept { - if (error()) { return error(); } - return std::forward(first).get_array(); -} -simdjson_really_inline simdjson_result simdjson_result::get_object() & noexcept { +simdjson_really_inline simdjson_result simdjson_result::get_object() noexcept { if (error()) { return error(); } return first.get_object(); } -simdjson_really_inline simdjson_result simdjson_result::get_object() && noexcept { - if (error()) { return error(); } - return std::forward(first).get_object(); -} simdjson_really_inline simdjson_result simdjson_result::get_uint64() noexcept { if (error()) { return error(); } return first.get_uint64(); @@ -293,59 +211,34 @@ simdjson_really_inline bool simdjson_result simdjson_really_inline simdjson_result simdjson_result::get() & noexcept { +template simdjson_really_inline simdjson_result simdjson_result::get() noexcept { if (error()) { return error(); } return first.get(); } -template simdjson_really_inline simdjson_result simdjson_result::get() && noexcept { - if (error()) { return error(); } - return std::forward(first).get(); -} -template simdjson_really_inline error_code simdjson_result::get(T &out) & noexcept { +template simdjson_really_inline error_code simdjson_result::get(T &out) noexcept { if (error()) { return error(); } return first.get(out); } -template simdjson_really_inline error_code simdjson_result::get(T &out) && noexcept { - if (error()) { return error(); } - return std::forward(first).get(out); -} -template<> simdjson_really_inline simdjson_result simdjson_result::get() & noexcept { +template<> simdjson_really_inline simdjson_result simdjson_result::get() noexcept { if (error()) { return error(); } return std::move(first); } -template<> simdjson_really_inline simdjson_result simdjson_result::get() && noexcept { - if (error()) { return error(); } - return std::forward(first); -} -template<> simdjson_really_inline error_code simdjson_result::get(SIMDJSON_IMPLEMENTATION::ondemand::value &out) & noexcept { +template<> simdjson_really_inline error_code simdjson_result::get(SIMDJSON_IMPLEMENTATION::ondemand::value &out) noexcept { if (error()) { return error(); } out = first; return SUCCESS; } -template<> simdjson_really_inline error_code simdjson_result::get(SIMDJSON_IMPLEMENTATION::ondemand::value &out) && noexcept { - if (error()) { return error(); } - out = std::forward(first); - return SUCCESS; -} #if SIMDJSON_EXCEPTIONS -simdjson_really_inline simdjson_result::operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(false) { +simdjson_really_inline simdjson_result::operator SIMDJSON_IMPLEMENTATION::ondemand::array() noexcept(false) { if (error()) { throw simdjson_error(error()); } return first; } -simdjson_really_inline simdjson_result::operator SIMDJSON_IMPLEMENTATION::ondemand::array() && noexcept(false) { - if (error()) { throw simdjson_error(error()); } - return std::forward(first); -} -simdjson_really_inline simdjson_result::operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(false) { +simdjson_really_inline simdjson_result::operator SIMDJSON_IMPLEMENTATION::ondemand::object() noexcept(false) { if (error()) { throw simdjson_error(error()); } return first; } -simdjson_really_inline simdjson_result::operator SIMDJSON_IMPLEMENTATION::ondemand::object() && noexcept(false) { - if (error()) { throw simdjson_error(error()); } - return std::forward(first); -} simdjson_really_inline simdjson_result::operator uint64_t() noexcept(false) { if (error()) { throw simdjson_error(error()); } return first; diff --git a/include/simdjson/generic/ondemand/value.h b/include/simdjson/generic/ondemand/value.h index 9b2dee87..fdeeafe1 100644 --- a/include/simdjson/generic/ondemand/value.h +++ b/include/simdjson/generic/ondemand/value.h @@ -30,9 +30,7 @@ public: * @returns A value of the given type, parsed from the JSON. * @returns INCORRECT_TYPE If the JSON value is not the given type. */ - template simdjson_really_inline simdjson_result get() & noexcept; - /** @overload template simdjson_result get() & noexcept */ - template simdjson_really_inline simdjson_result get() && noexcept; + template simdjson_really_inline simdjson_result get() noexcept; /** * Get this value as the given type. @@ -43,9 +41,7 @@ public: * @returns INCORRECT_TYPE If the JSON value is not an object. * @returns SUCCESS If the parse succeeded and the out parameter was set to the value. */ - template simdjson_really_inline error_code get(T &out) & noexcept; - /** @overload template error_code get(T &out) & noexcept */ - template simdjson_really_inline error_code get(T &out) && noexcept; + template simdjson_really_inline error_code get(T &out) noexcept; /** * Cast this JSON value to an array. @@ -53,9 +49,7 @@ public: * @returns An object that can be used to iterate the array. * @returns INCORRECT_TYPE If the JSON value is not an array. */ - simdjson_really_inline simdjson_result get_array() && noexcept; - /** @overload simdjson_really_inline operator get_array() && noexcept(false); */ - simdjson_really_inline simdjson_result get_array() & noexcept; + simdjson_really_inline simdjson_result get_array() noexcept; /** * Cast this JSON value to an object. @@ -63,9 +57,7 @@ public: * @returns An object that can be used to look up or iterate fields. * @returns INCORRECT_TYPE If the JSON value is not an object. */ - simdjson_really_inline simdjson_result get_object() && noexcept; - /** @overload simdjson_really_inline operator object() && noexcept(false); */ - simdjson_really_inline simdjson_result get_object() & noexcept; + simdjson_really_inline simdjson_result get_object() noexcept; /** * Cast this JSON value to an unsigned integer. @@ -136,18 +128,14 @@ public: * @returns An object that can be used to iterate the array. * @exception simdjson_error(INCORRECT_TYPE) If the JSON value is not an array. */ - simdjson_really_inline operator array() && noexcept(false); - /** @overload simdjson_really_inline operator array() && noexcept(false); */ - simdjson_really_inline operator array() & noexcept(false); + simdjson_really_inline operator array() noexcept(false); /** * Cast this JSON value to an object. * * @returns An object that can be used to look up or iterate fields. * @exception simdjson_error(INCORRECT_TYPE) If the JSON value is not an object. */ - simdjson_really_inline operator object() && noexcept(false); - /** @overload simdjson_really_inline operator object() && noexcept(false); */ - simdjson_really_inline operator object() & noexcept(false); + simdjson_really_inline operator object() noexcept(false); /** * Cast this JSON value to an unsigned integer. * @@ -234,13 +222,9 @@ public: * @param key The key to look up. * @returns The value of the field, or NO_SUCH_FIELD if the field is not in the object. */ - simdjson_really_inline simdjson_result find_field(std::string_view key) & noexcept; - /** @overload simdjson_really_inline simdjson_result find_field(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result find_field(std::string_view key) && noexcept; - /** @overload simdjson_really_inline simdjson_result find_field(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result find_field(const char *key) & noexcept; - /** @overload simdjson_really_inline simdjson_result find_field(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result find_field(const char *key) && noexcept; + simdjson_really_inline simdjson_result find_field(std::string_view key) noexcept; + /** @overload simdjson_really_inline simdjson_result find_field(std::string_view key) noexcept; */ + simdjson_really_inline simdjson_result find_field(const char *key) noexcept; /** * Look up a field by name on an object, without regard to key order. @@ -261,21 +245,13 @@ public: * @param key The key to look up. * @returns The value of the field, or NO_SUCH_FIELD if the field is not in the object. */ - simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) & noexcept; - /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) && noexcept; - /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result find_field_unordered(const char *key) & noexcept; - /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result find_field_unordered(const char *key) && noexcept; - /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result operator[](std::string_view key) & noexcept; - /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result operator[](std::string_view key) && noexcept; - /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result operator[](const char *key) & noexcept; - /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result operator[](const char *key) && noexcept; + simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) noexcept; + /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) noexcept; */ + simdjson_really_inline simdjson_result find_field_unordered(const char *key) noexcept; + /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) noexcept; */ + simdjson_really_inline simdjson_result operator[](std::string_view key) noexcept; + /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) noexcept; */ + simdjson_really_inline simdjson_result operator[](const char *key) noexcept; protected: /** @@ -303,9 +279,7 @@ protected: /** * Get the object, starting or resuming it as necessary */ - simdjson_really_inline simdjson_result start_or_resume_object() & noexcept; - /** @overload simdjson_really_inline simdjson_result start_or_resume_object() & noexcept; */ - simdjson_really_inline simdjson_result start_or_resume_object() && noexcept; + simdjson_really_inline simdjson_result start_or_resume_object() noexcept; // simdjson_really_inline void log_value(const char *type) const noexcept; // simdjson_really_inline void log_error(const char *message) const noexcept; @@ -334,11 +308,8 @@ public: simdjson_really_inline simdjson_result(error_code error) noexcept; ///< @private simdjson_really_inline simdjson_result() noexcept = default; - simdjson_really_inline simdjson_result get_array() && noexcept; - simdjson_really_inline simdjson_result get_array() & noexcept; - - simdjson_really_inline simdjson_result get_object() && noexcept; - simdjson_really_inline simdjson_result get_object() & noexcept; + simdjson_really_inline simdjson_result get_array() noexcept; + simdjson_really_inline simdjson_result get_object() noexcept; simdjson_really_inline simdjson_result get_uint64() noexcept; simdjson_really_inline simdjson_result get_int64() noexcept; @@ -348,17 +319,13 @@ public: simdjson_really_inline simdjson_result get_bool() noexcept; simdjson_really_inline bool is_null() noexcept; - template simdjson_really_inline simdjson_result get() & noexcept; - template simdjson_really_inline simdjson_result get() && noexcept; + template simdjson_really_inline simdjson_result get() noexcept; - template simdjson_really_inline error_code get(T &out) & noexcept; - template simdjson_really_inline error_code get(T &out) && noexcept; + template simdjson_really_inline error_code get(T &out) noexcept; #if SIMDJSON_EXCEPTIONS - simdjson_really_inline operator SIMDJSON_IMPLEMENTATION::ondemand::array() && noexcept(false); - simdjson_really_inline operator SIMDJSON_IMPLEMENTATION::ondemand::array() & noexcept(false); - simdjson_really_inline operator SIMDJSON_IMPLEMENTATION::ondemand::object() && noexcept(false); - simdjson_really_inline operator SIMDJSON_IMPLEMENTATION::ondemand::object() & noexcept(false); + simdjson_really_inline operator SIMDJSON_IMPLEMENTATION::ondemand::array() noexcept(false); + simdjson_really_inline operator SIMDJSON_IMPLEMENTATION::ondemand::object() noexcept(false); simdjson_really_inline operator uint64_t() noexcept(false); simdjson_really_inline operator int64_t() noexcept(false); simdjson_really_inline operator double() noexcept(false); @@ -390,13 +357,9 @@ public: * @param key The key to look up. * @returns The value of the field, or NO_SUCH_FIELD if the field is not in the object. */ - simdjson_really_inline simdjson_result find_field(std::string_view key) & noexcept; - /** @overload simdjson_really_inline simdjson_result find_field(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result find_field(std::string_view key) && noexcept; - /** @overload simdjson_really_inline simdjson_result find_field(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result find_field(const char *key) & noexcept; - /** @overload simdjson_really_inline simdjson_result find_field(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result find_field(const char *key) && noexcept; + simdjson_really_inline simdjson_result find_field(std::string_view key) noexcept; + /** @overload simdjson_really_inline simdjson_result find_field(std::string_view key) noexcept; */ + simdjson_really_inline simdjson_result find_field(const char *key) noexcept; /** * Look up a field by name on an object, without regard to key order. @@ -417,21 +380,13 @@ public: * @param key The key to look up. * @returns The value of the field, or NO_SUCH_FIELD if the field is not in the object. */ - simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) & noexcept; - /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) && noexcept; - /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result find_field_unordered(const char *key) & noexcept; - /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result find_field_unordered(const char *key) && noexcept; - /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result operator[](std::string_view key) & noexcept; - /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result operator[](std::string_view key) && noexcept; - /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result operator[](const char *key) & noexcept; - /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) & noexcept; */ - simdjson_really_inline simdjson_result operator[](const char *key) && noexcept; + simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) noexcept; + /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) noexcept; */ + simdjson_really_inline simdjson_result find_field_unordered(const char *key) noexcept; + /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) noexcept; */ + simdjson_really_inline simdjson_result operator[](std::string_view key) noexcept; + /** @overload simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) noexcept; */ + simdjson_really_inline simdjson_result operator[](const char *key) noexcept; }; } // namespace simdjson diff --git a/include/simdjson/generic/ondemand/value_iterator-inl.h b/include/simdjson/generic/ondemand/value_iterator-inl.h index 76219deb..fd21ea0b 100644 --- a/include/simdjson/generic/ondemand/value_iterator-inl.h +++ b/include/simdjson/generic/ondemand/value_iterator-inl.h @@ -10,20 +10,12 @@ simdjson_really_inline value_iterator::value_iterator(json_iterator *json_iter, } simdjson_warn_unused simdjson_really_inline simdjson_result value_iterator::start_object() noexcept { - assert_at_start(); - - if (*_json_iter->advance() != '{') { logger::log_error(*_json_iter, "Not an object"); return INCORRECT_TYPE; } - return started_object(); -} -simdjson_warn_unused simdjson_really_inline simdjson_result value_iterator::try_start_object() noexcept { - assert_at_start(); - - if (*_json_iter->peek() != '{') { logger::log_error(*_json_iter, "Not an object"); return INCORRECT_TYPE; } - _json_iter->advance(); + if (*advance_container_start("object") != '{') { return incorrect_type_error("Not an object"); } return started_object(); } simdjson_warn_unused simdjson_really_inline bool value_iterator::started_object() noexcept { + assert_at_container_start(); if (*_json_iter->peek() == '}') { logger::log_value(*_json_iter, "empty object"); _json_iter->advance(); @@ -256,21 +248,12 @@ simdjson_warn_unused simdjson_really_inline error_code value_iterator::field_val } simdjson_warn_unused simdjson_really_inline simdjson_result value_iterator::start_array() noexcept { - assert_at_start(); - - if (*_json_iter->advance() != '[') { logger::log_error(*_json_iter, "Not an array"); return INCORRECT_TYPE; } - return started_array(); -} - -simdjson_warn_unused simdjson_really_inline simdjson_result value_iterator::try_start_array() noexcept { - assert_at_start(); - - if (*_json_iter->peek() != '[') { logger::log_error(*_json_iter, "Not an array"); return INCORRECT_TYPE; } - _json_iter->advance(); + if (*advance_container_start("array") != '[') { return incorrect_type_error("Not an array"); } return started_array(); } simdjson_warn_unused simdjson_really_inline bool value_iterator::started_array() noexcept { + assert_at_container_start(); if (*_json_iter->peek() == ']') { logger::log_value(*_json_iter, "empty array"); _json_iter->advance(); @@ -313,7 +296,7 @@ simdjson_warn_unused simdjson_really_inline simdjson_result va return get_raw_json_string().unescape(_json_iter->string_buf_loc()); } simdjson_warn_unused simdjson_really_inline simdjson_result value_iterator::get_raw_json_string() noexcept { - auto json = advance_scalar("string"); + auto json = advance_start("string"); if (*json != '"') { return incorrect_type_error("Not a string"); } return raw_json_string(json+1); } @@ -342,21 +325,21 @@ simdjson_warn_unused simdjson_really_inline simdjson_result val return get_raw_json_string(); } simdjson_warn_unused simdjson_really_inline simdjson_result value_iterator::get_root_uint64() noexcept { - auto max_len = peek_scalar_length(); + auto max_len = peek_start_length(); auto json = advance_root_scalar("uint64"); uint8_t tmpbuf[20+1]; // <20 digits> is the longest possible unsigned integer if (!_json_iter->copy_to_buffer(json, max_len, tmpbuf)) { logger::log_error(*_json_iter, _start_position, depth(), "Root number more than 20 characters"); return NUMBER_ERROR; } return numberparsing::parse_unsigned(tmpbuf); } simdjson_warn_unused simdjson_really_inline simdjson_result value_iterator::get_root_int64() noexcept { - auto max_len = peek_scalar_length(); + auto max_len = peek_start_length(); auto json = advance_root_scalar("int64"); uint8_t tmpbuf[20+1]; // -<19 digits> is the longest possible integer if (!_json_iter->copy_to_buffer(json, max_len, tmpbuf)) { logger::log_error(*_json_iter, _start_position, depth(), "Root number more than 20 characters"); return NUMBER_ERROR; } return numberparsing::parse_integer(tmpbuf); } simdjson_warn_unused simdjson_really_inline simdjson_result value_iterator::get_root_double() noexcept { - auto max_len = peek_scalar_length(); + auto max_len = peek_start_length(); auto json = advance_root_scalar("double"); // Per https://www.exploringbinary.com/maximum-number-of-decimal-digits-in-binary-floating-point-numbers/, 1074 is the maximum number of significant fractional digits. Add 8 more digits for the biggest number: -0.e-308. uint8_t tmpbuf[1074+8+1]; @@ -364,14 +347,14 @@ simdjson_warn_unused simdjson_really_inline simdjson_result value_iterat return numberparsing::parse_double(tmpbuf); } simdjson_warn_unused simdjson_really_inline simdjson_result value_iterator::get_root_bool() noexcept { - auto max_len = peek_scalar_length(); + auto max_len = peek_start_length(); auto json = advance_root_scalar("bool"); uint8_t tmpbuf[5+1]; if (!_json_iter->copy_to_buffer(json, max_len, tmpbuf)) { return incorrect_type_error("Not a boolean"); } return parse_bool(tmpbuf); } simdjson_really_inline bool value_iterator::is_root_null() noexcept { - auto max_len = peek_scalar_length(); + auto max_len = peek_start_length(); auto json = advance_root_scalar("null"); return max_len >= 4 && !atomparsing::str4ncmp(json, "null") && (max_len == 4 || jsoncharutils::is_structural_or_whitespace(json[5])); @@ -427,17 +410,17 @@ simdjson_warn_unused simdjson_really_inline json_iterator &value_iterator::json_ return *_json_iter; } -simdjson_really_inline const uint8_t *value_iterator::peek_scalar() const noexcept { +simdjson_really_inline const uint8_t *value_iterator::peek_start() const noexcept { return _json_iter->peek(_start_position); } -simdjson_really_inline uint32_t value_iterator::peek_scalar_length() const noexcept { +simdjson_really_inline uint32_t value_iterator::peek_start_length() const noexcept { return _json_iter->peek_length(_start_position); } -simdjson_really_inline const uint8_t *value_iterator::advance_scalar(const char *type) const noexcept { +simdjson_really_inline const uint8_t *value_iterator::advance_start(const char *type) const noexcept { logger::log_value(*_json_iter, _start_position, depth(), type); // If we're not at the position anymore, we don't want to advance the cursor. - if (!is_at_start()) { return peek_scalar(); } + if (!is_at_start()) { return peek_start(); } // Get the JSON and advance the cursor, decreasing depth to signify that we have retrieved the value. assert_at_start(); @@ -445,9 +428,19 @@ simdjson_really_inline const uint8_t *value_iterator::advance_scalar(const char _json_iter->ascend_to(depth()-1); return result; } +simdjson_really_inline const uint8_t *value_iterator::advance_container_start(const char *type) const noexcept { + // If we're not at the position anymore, we don't want to advance the cursor. + if (is_at_container_start()) { return peek_start(); } + + logger::log_start_value(*_json_iter, _start_position, depth(), type); + + // Get the JSON and advance the cursor, decreasing depth to signify that we have retrieved the value. + assert_at_start(); + return _json_iter->advance(); +} simdjson_really_inline const uint8_t *value_iterator::advance_root_scalar(const char *type) const noexcept { logger::log_value(*_json_iter, _start_position, depth(), type); - if (!is_at_start()) { return peek_scalar(); } + if (!is_at_start()) { return peek_start(); } assert_at_root(); auto result = _json_iter->advance(); @@ -456,7 +449,7 @@ simdjson_really_inline const uint8_t *value_iterator::advance_root_scalar(const } simdjson_really_inline const uint8_t *value_iterator::advance_non_root_scalar(const char *type) const noexcept { logger::log_value(*_json_iter, _start_position, depth(), type); - if (!is_at_start()) { return peek_scalar(); } + if (!is_at_start()) { return peek_start(); } assert_at_non_root_start(); auto result = _json_iter->advance(); @@ -472,6 +465,9 @@ simdjson_really_inline error_code value_iterator::incorrect_type_error(const cha simdjson_really_inline bool value_iterator::is_at_start() const noexcept { return _json_iter->token.index == _start_position; } +simdjson_really_inline bool value_iterator::is_at_container_start() const noexcept { + return _json_iter->token.index == _start_position + 1; +} simdjson_really_inline void value_iterator::assert_at_start() const noexcept { SIMDJSON_ASSUME( _json_iter->token.index == _start_position ); @@ -479,6 +475,12 @@ simdjson_really_inline void value_iterator::assert_at_start() const noexcept { SIMDJSON_ASSUME( _depth > 0 ); } +simdjson_really_inline void value_iterator::assert_at_container_start() const noexcept { + SIMDJSON_ASSUME( _json_iter->token.index == _start_position + 1 ); + SIMDJSON_ASSUME( _json_iter->_depth == _depth ); + SIMDJSON_ASSUME( _depth > 0 ); +} + simdjson_really_inline void value_iterator::assert_at_next() const noexcept { SIMDJSON_ASSUME( _json_iter->token.index > _start_position ); SIMDJSON_ASSUME( _json_iter->_depth == _depth ); diff --git a/include/simdjson/generic/ondemand/value_iterator.h b/include/simdjson/generic/ondemand/value_iterator.h index 60a2942a..a11d1e2e 100644 --- a/include/simdjson/generic/ondemand/value_iterator.h +++ b/include/simdjson/generic/ondemand/value_iterator.h @@ -208,13 +208,6 @@ public: * @error INCORRECT_TYPE If there is no [. */ simdjson_warn_unused simdjson_really_inline simdjson_result start_array() noexcept; - /** - * Check for an opening [ and start an array iteration. - * - * @returns Whether the array had any elements (returns false for empty). - * @error INCORRECT_TYPE If there is no [. - */ - simdjson_warn_unused simdjson_really_inline simdjson_result try_start_array() noexcept; /** * Start an array iteration after the user has already checked and moved past the [. @@ -278,16 +271,19 @@ protected: simdjson_really_inline bool parse_null(const uint8_t *json) const noexcept; simdjson_really_inline simdjson_result parse_bool(const uint8_t *json) const noexcept; - simdjson_really_inline const uint8_t *peek_scalar() const noexcept; - simdjson_really_inline uint32_t peek_scalar_length() const noexcept; - simdjson_really_inline const uint8_t *advance_scalar(const char *type) const noexcept; + simdjson_really_inline const uint8_t *peek_start() const noexcept; + simdjson_really_inline uint32_t peek_start_length() const noexcept; + simdjson_really_inline const uint8_t *advance_start(const char *type) const noexcept; + simdjson_really_inline const uint8_t *advance_container_start(const char *type) const noexcept; simdjson_really_inline const uint8_t *advance_root_scalar(const char *type) const noexcept; simdjson_really_inline const uint8_t *advance_non_root_scalar(const char *type) const noexcept; simdjson_really_inline error_code incorrect_type_error(const char *message) const noexcept; simdjson_really_inline bool is_at_start() const noexcept; + simdjson_really_inline bool is_at_container_start() const noexcept; simdjson_really_inline void assert_at_start() const noexcept; + simdjson_really_inline void assert_at_container_start() const noexcept; simdjson_really_inline void assert_at_root() const noexcept; simdjson_really_inline void assert_at_child() const noexcept; simdjson_really_inline void assert_at_next() const noexcept; diff --git a/tests/ondemand/ondemand_dom_api_tests.cpp b/tests/ondemand/ondemand_dom_api_tests.cpp index c58f2d47..12040957 100644 --- a/tests/ondemand/ondemand_dom_api_tests.cpp +++ b/tests/ondemand/ondemand_dom_api_tests.cpp @@ -47,6 +47,7 @@ namespace dom_api_tests { SUBTEST("ondemand::array", test_ondemand_doc(json, [&](auto doc_result) { ondemand::array array; ASSERT_SUCCESS( doc_result.get(array) ); + size_t i=0; for (auto value : array) { int64_t actual; diff --git a/tests/test_macros.h b/tests/test_macros.h index d7561b7f..b0638eac 100644 --- a/tests/test_macros.h +++ b/tests/test_macros.h @@ -48,7 +48,7 @@ template simdjson_really_inline bool assert_success(const T &actual, const char *operation = "result") { simdjson::error_code error = to_error_code(actual); if (error) { - std::cerr << "FAIL: " << operation << " returned error: " << error << std::endl; + std::cerr << "FAIL: " << operation << " returned error: " << error << " (" << int(error) << ")" << std::endl; return false; } return true;