Disable all OUT_OF_ORDER_ITERATION checks when SIMDJSON_API_USAGE_CHECKS
is off
This commit is contained in:
parent
c7935ceed1
commit
3801ea7777
|
@ -56,7 +56,9 @@ simdjson_really_inline array array::started(value_iterator &iter) noexcept {
|
|||
}
|
||||
|
||||
simdjson_really_inline simdjson_result<array_iterator> 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_iterator> array::end() noexcept {
|
||||
|
|
|
@ -52,7 +52,9 @@ simdjson_really_inline object::object(const value_iterator &_iter) noexcept
|
|||
}
|
||||
|
||||
simdjson_really_inline simdjson_result<object_iterator> 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_iterator> object::end() noexcept {
|
||||
|
|
|
@ -71,10 +71,12 @@ simdjson_warn_unused simdjson_really_inline simdjson_result<bool> 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<bool> 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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue