Add partial out-of-order check for field lookup

This commit is contained in:
John Keiser 2021-01-24 19:44:45 -08:00
parent 22b3ea93a8
commit c5b44f44f9
1 changed files with 7 additions and 1 deletions

View File

@ -68,7 +68,13 @@ simdjson_warn_unused simdjson_really_inline simdjson_result<bool> value_iterator
// ^ (depth 0, index 2)
// ```
//
if (!is_open()) { return false; }
if (!is_open()) {
// 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; }
return false;
}
if (at_first_field()) {
has_value = true;