Don't emit out of order iteration error for empty array

This commit is contained in:
John Keiser 2021-02-21 11:42:27 -08:00
parent b352b903e7
commit 0634958329
4 changed files with 8 additions and 3 deletions

View File

@ -57,7 +57,7 @@ simdjson_really_inline array array::started(value_iterator &iter) noexcept {
simdjson_really_inline simdjson_result<array_iterator> array::begin() noexcept { simdjson_really_inline simdjson_result<array_iterator> array::begin() noexcept {
#ifdef SIMDJSON_DEVELOPMENT_CHECKS #ifdef SIMDJSON_DEVELOPMENT_CHECKS
if (!iter.is_at_container_start()) { return OUT_OF_ORDER_ITERATION; } if (!iter.is_at_iterator_start()) { return OUT_OF_ORDER_ITERATION; }
#endif #endif
return array_iterator(iter); return array_iterator(iter);
} }

View File

@ -53,7 +53,7 @@ simdjson_really_inline object::object(const value_iterator &_iter) noexcept
simdjson_really_inline simdjson_result<object_iterator> object::begin() noexcept { simdjson_really_inline simdjson_result<object_iterator> object::begin() noexcept {
#ifdef SIMDJSON_DEVELOPMENT_CHECKS #ifdef SIMDJSON_DEVELOPMENT_CHECKS
if (!iter.is_at_container_start()) { return OUT_OF_ORDER_ITERATION; } if (!iter.is_at_iterator_start()) { return OUT_OF_ORDER_ITERATION; }
#endif #endif
return object_iterator(iter); return object_iterator(iter);
} }

View File

@ -462,7 +462,7 @@ 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 we're not at the position anymore, we don't want to advance the cursor.
if (!is_at_start()) { if (!is_at_start()) {
#ifdef SIMDJSON_DEVELOPMENT_CHECKS #ifdef SIMDJSON_DEVELOPMENT_CHECKS
if (!is_at_container_start()) { return OUT_OF_ORDER_ITERATION; } if (!is_at_iterator_start()) { return OUT_OF_ORDER_ITERATION; }
#endif #endif
json = peek_start(); json = peek_start();
return SUCCESS; return SUCCESS;
@ -503,6 +503,10 @@ simdjson_really_inline bool value_iterator::is_at_start() const noexcept {
simdjson_really_inline bool value_iterator::is_at_container_start() const noexcept { simdjson_really_inline bool value_iterator::is_at_container_start() const noexcept {
return _json_iter->token.index == _start_position + 1; return _json_iter->token.index == _start_position + 1;
} }
simdjson_really_inline bool value_iterator::is_at_iterator_start() const noexcept {
auto delta = _json_iter->token.index - _start_position;
return delta == 1 || delta == 2;
}
simdjson_really_inline void value_iterator::assert_at_start() const noexcept { simdjson_really_inline void value_iterator::assert_at_start() const noexcept {
SIMDJSON_ASSUME( _json_iter->token.index == _start_position ); SIMDJSON_ASSUME( _json_iter->token.index == _start_position );

View File

@ -285,6 +285,7 @@ protected:
simdjson_really_inline bool is_at_start() const noexcept; simdjson_really_inline bool is_at_start() const noexcept;
simdjson_really_inline bool is_at_container_start() const noexcept; simdjson_really_inline bool is_at_container_start() const noexcept;
simdjson_really_inline bool is_at_iterator_start() const noexcept;
simdjson_really_inline void assert_at_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_container_start() const noexcept;
simdjson_really_inline void assert_at_root() const noexcept; simdjson_really_inline void assert_at_root() const noexcept;