1 namespace simdjson { 2 namespace SIMDJSON_IMPLEMENTATION { 3 namespace ondemand { 4 array_iterator(const value_iterator & _iter)5simdjson_really_inline array_iterator::array_iterator(const value_iterator &_iter) noexcept 6 : iter{_iter} 7 {} 8 9 simdjson_really_inline simdjson_result<value> array_iterator::operator*() noexcept { 10 if (iter.error()) { iter.abandon(); return iter.error(); } 11 return value(iter.child()); 12 } 13 simdjson_really_inline bool array_iterator::operator==(const array_iterator &other) const noexcept { 14 return !(*this != other); 15 } 16 simdjson_really_inline bool array_iterator::operator!=(const array_iterator &) const noexcept { 17 return iter.is_open(); 18 } 19 simdjson_really_inline array_iterator &array_iterator::operator++() noexcept { 20 error_code error; 21 // PERF NOTE this is a safety rail ... users should exit loops as soon as they receive an error, so we'll never get here. 22 // However, it does not seem to make a perf difference, so we add it out of an abundance of caution. 23 if ((error = iter.error()) ) { return *this; } 24 if ((error = iter.skip_child() )) { return *this; } 25 if ((error = iter.has_next_element().error() )) { return *this; } 26 return *this; 27 } 28 29 } // namespace ondemand 30 } // namespace SIMDJSON_IMPLEMENTATION 31 } // namespace simdjson 32 33 namespace simdjson { 34 simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::array_iterator && value)35simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::simdjson_result( 36 SIMDJSON_IMPLEMENTATION::ondemand::array_iterator &&value 37 ) noexcept 38 : SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>(std::forward<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>(value)) 39 { 40 first.iter.assert_is_valid(); 41 } simdjson_result(error_code error)42simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::simdjson_result(error_code error) noexcept 43 : SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>({}, error) 44 { 45 } 46 47 simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::operator*() noexcept { 48 if (error()) { return error(); } 49 return *first; 50 } 51 simdjson_really_inline bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::operator==(const simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> &other) const noexcept { 52 if (!first.iter.is_valid()) { return !error(); } 53 return first == other.first; 54 } 55 simdjson_really_inline bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::operator!=(const simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> &other) const noexcept { 56 if (!first.iter.is_valid()) { return error(); } 57 return first != other.first; 58 } 59 simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator> &simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array_iterator>::operator++() noexcept { 60 // Clear the error if there is one, so we don't yield it twice 61 if (error()) { second = SUCCESS; return *this; } 62 ++(first); 63 return *this; 64 } 65 66 } // namespace simdjson 67