@@ -41,23 +41,22 @@ namespace ondemand {
41
41
//
42
42
43
43
simdjson_really_inline array::array () noexcept = default;
44
- simdjson_really_inline array::array (json_iterator_ref &&_iter, bool has_value ) noexcept
45
- : iter{std::forward<json_iterator_ref>(_iter)}, has_next{has_value}, error{SUCCESS}
44
+ simdjson_really_inline array::array (json_iterator_ref &&_iter) noexcept
45
+ : iter{std::forward<json_iterator_ref>(_iter)}, error{SUCCESS}
46
46
{
47
47
}
48
48
simdjson_really_inline array::array (array &&other) noexcept
49
- : iter{std::forward<array>(other).iter }, has_next{other. has_next }, error{other.error }
49
+ : iter{std::forward<array>(other).iter }, error{other.error }
50
50
{
51
51
}
52
52
simdjson_really_inline array &array::operator =(array &&other) noexcept {
53
53
iter = std::forward<array>(other).iter ;
54
- has_next = other.has_next ;
55
54
error = other.error ;
56
55
return *this ;
57
56
}
58
57
59
58
simdjson_really_inline array::~array () noexcept {
60
- if (!error && has_next && iter.is_alive ()) {
59
+ if (iter.is_alive ()) {
61
60
logger::log_event (*iter, " unfinished" , " array" );
62
61
iter->skip_container ();
63
62
iter.release ();
@@ -67,10 +66,12 @@ simdjson_really_inline array::~array() noexcept {
67
66
simdjson_really_inline simdjson_result<array> array::start (json_iterator_ref &&iter) noexcept {
68
67
bool has_value;
69
68
SIMDJSON_TRY ( iter->start_array ().get (has_value) );
70
- return array (std::forward<json_iterator_ref>(iter), has_value);
69
+ if (!has_value) { iter.release (); }
70
+ return array (std::forward<json_iterator_ref>(iter));
71
71
}
72
72
simdjson_really_inline array array::started (json_iterator_ref &&iter) noexcept {
73
- return array (std::forward<json_iterator_ref>(iter), iter->started_array ());
73
+ if (!iter->started_array ()) { iter.release (); }
74
+ return array (std::forward<json_iterator_ref>(iter));
74
75
}
75
76
simdjson_really_inline array::iterator array::begin () noexcept {
76
77
return *this ;
@@ -79,31 +80,26 @@ simdjson_really_inline array::iterator array::end() noexcept {
79
80
return *this ;
80
81
}
81
82
82
- simdjson_really_inline error_code array::report_error () noexcept {
83
- SIMDJSON_ASSUME (error);
84
- has_next = false ;
85
- return error;
86
- }
87
-
88
83
simdjson_really_inline array::iterator::iterator (array &_a) noexcept : a{&_a} {}
89
84
90
85
simdjson_really_inline array::iterator::iterator () noexcept = default;
91
86
simdjson_really_inline array::iterator::iterator (const array::iterator &_a) noexcept = default;
92
87
simdjson_really_inline array::iterator &array::iterator::operator =(const array::iterator &_a) noexcept = default ;
93
88
94
89
simdjson_really_inline simdjson_result<value> array::iterator::operator *() noexcept {
95
- if (a->error ) { return a->report_error () ; }
90
+ if (a->error ) { a->iter . release (); return a-> error ; }
96
91
return value::start (a->iter .borrow ());
97
92
}
98
93
simdjson_really_inline bool array::iterator::operator ==(const array::iterator &other) noexcept {
99
94
return !(*this != other);
100
95
}
101
96
simdjson_really_inline bool array::iterator::operator !=(const array::iterator &) noexcept {
102
- return a->has_next ;
97
+ return a->iter . is_alive () ;
103
98
}
104
99
simdjson_really_inline array::iterator &array::iterator::operator ++() noexcept {
105
- a->error = a->iter ->has_next_element ().get (a->has_next ); // If there's an error, has_next stays true.
106
- if (!a->error && !a->has_next ) { a->iter .release (); }
100
+ bool has_value;
101
+ a->error = a->iter ->has_next_element ().get (has_value); // If there's an error, has_next stays true.
102
+ if (!(a->error || has_value)) { a->iter .release (); }
107
103
return *this ;
108
104
}
109
105
0 commit comments