From 3801ea777762d79327ee1f10ad11fae7e08b6003 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Fri, 5 Feb 2021 15:33:18 -0800 Subject: [PATCH] Disable all OUT_OF_ORDER_ITERATION checks when SIMDJSON_API_USAGE_CHECKS is off --- include/simdjson/generic/ondemand/array-inl.h | 2 ++ include/simdjson/generic/ondemand/object-inl.h | 2 ++ include/simdjson/generic/ondemand/value_iterator-inl.h | 6 ++++++ tests/ondemand/ondemand_error_tests.cpp | 4 ++++ 4 files changed, 14 insertions(+) diff --git a/include/simdjson/generic/ondemand/array-inl.h b/include/simdjson/generic/ondemand/array-inl.h index 3d11c527..67bf9a1b 100644 --- a/include/simdjson/generic/ondemand/array-inl.h +++ b/include/simdjson/generic/ondemand/array-inl.h @@ -56,7 +56,9 @@ simdjson_really_inline array array::started(value_iterator &iter) noexcept { } simdjson_really_inline simdjson_result array::begin() noexcept { +#if SIMDJSON_API_USAGE_CHECKS if (!iter.is_at_container_start()) { return OUT_OF_ORDER_ITERATION; } +#endif return array_iterator(iter); } simdjson_really_inline simdjson_result array::end() noexcept { diff --git a/include/simdjson/generic/ondemand/object-inl.h b/include/simdjson/generic/ondemand/object-inl.h index 77954281..6bdff16f 100644 --- a/include/simdjson/generic/ondemand/object-inl.h +++ b/include/simdjson/generic/ondemand/object-inl.h @@ -52,7 +52,9 @@ simdjson_really_inline object::object(const value_iterator &_iter) noexcept } simdjson_really_inline simdjson_result object::begin() noexcept { +#if SIMDJSON_API_USAGE_CHECKS if (!iter.is_at_container_start()) { return OUT_OF_ORDER_ITERATION; } +#endif return object_iterator(iter); } simdjson_really_inline simdjson_result object::end() noexcept { diff --git a/include/simdjson/generic/ondemand/value_iterator-inl.h b/include/simdjson/generic/ondemand/value_iterator-inl.h index 54b41491..8f6d262c 100644 --- a/include/simdjson/generic/ondemand/value_iterator-inl.h +++ b/include/simdjson/generic/ondemand/value_iterator-inl.h @@ -71,10 +71,12 @@ simdjson_warn_unused simdjson_really_inline simdjson_result value_iterator // ``` // } else if (!is_open()) { +#if SIMDJSON_API_USAGE_CHECKS // If we're past the end of the object, we're being iterated out of order. // Note: this isn't perfect detection. It's possible the user is inside some other object; if so, // this object iterator will blithely scan that object for fields. if (_json_iter->depth() < depth() - 1) { return OUT_OF_ORDER_ITERATION; } +#endif has_value = false; // 3. When a previous search found a field or an iterator yielded a value: @@ -148,10 +150,12 @@ simdjson_warn_unused simdjson_really_inline simdjson_result value_iterator // ``` // } else if (!is_open()) { +#if SIMDJSON_API_USAGE_CHECKS // If we're past the end of the object, we're being iterated out of order. // Note: this isn't perfect detection. It's possible the user is inside some other object; if so, // this object iterator will blithely scan that object for fields. if (_json_iter->depth() < depth() - 1) { return OUT_OF_ORDER_ITERATION; } +#endif has_value = false; // 3. When a previous search found a field or an iterator yielded a value: @@ -452,7 +456,9 @@ simdjson_really_inline error_code value_iterator::advance_container_start(const // If we're not at the position anymore, we don't want to advance the cursor. if (!is_at_start()) { +#if SIMDJSON_API_USAGE_CHECKS if (!is_at_container_start()) { return OUT_OF_ORDER_ITERATION; } +#endif json = peek_start(); return SUCCESS; } diff --git a/tests/ondemand/ondemand_error_tests.cpp b/tests/ondemand/ondemand_error_tests.cpp index d4bbe0a0..34a0f174 100644 --- a/tests/ondemand/ondemand_error_tests.cpp +++ b/tests/ondemand/ondemand_error_tests.cpp @@ -565,6 +565,7 @@ namespace error_tests { TEST_SUCCEED(); } +#if SIMDJSON_API_USAGE_CHECKS bool out_of_order_array_iteration_error() { TEST_START(); auto json = R"([ [ 1, 2 ] ])"_padded; @@ -698,6 +699,7 @@ namespace error_tests { })); TEST_SUCCEED(); } +#endif bool run() { return @@ -718,11 +720,13 @@ namespace error_tests { object_lookup_miss_next_error() && get_fail_then_succeed_bool() && get_fail_then_succeed_null() && +#if SIMDJSON_API_USAGE_CHECKS out_of_order_array_iteration_error() && out_of_order_object_iteration_error() && out_of_order_object_index_error() && out_of_order_object_find_field_error() && out_of_order_object_find_field_unordered_error() && +#endif true; } }