@@ -44,28 +44,23 @@ namespace ondemand {
44
44
//
45
45
46
46
simdjson_really_inline object::object () noexcept = default;
47
- simdjson_really_inline object::object (json_iterator_ref &&_iter, bool _has_value ) noexcept
48
- : iter{std::forward<json_iterator_ref>(_iter)}, has_next{_has_value}, at_start{true }, error{SUCCESS}
47
+ simdjson_really_inline object::object (json_iterator_ref &&_iter) noexcept
48
+ : iter{std::forward<json_iterator_ref>(_iter)}, at_start{true }, error{SUCCESS}
49
49
{
50
50
}
51
51
simdjson_really_inline object::object (object &&other) noexcept
52
- : iter{std::forward<object>(other).iter }, has_next{other. has_next }, at_start{other.at_start }, error{other.error }
52
+ : iter{std::forward<object>(other).iter }, at_start{other.at_start }, error{other.error }
53
53
{
54
- // Terminate the other iterator
55
- other.has_next = false ;
56
54
}
57
55
simdjson_really_inline object &object::operator =(object &&other) noexcept {
58
56
iter = std::forward<object>(other).iter ;
59
- has_next = other.has_next ;
60
57
at_start = other.at_start ;
61
58
error = other.error ;
62
- // Terminate the other iterator
63
- other.has_next = false ;
64
59
return *this ;
65
60
}
66
61
67
62
simdjson_really_inline object::~object () noexcept {
68
- if (!error && has_next && iter.is_alive ()) {
63
+ if (iter.is_alive ()) {
69
64
logger::log_event (*iter, " unfinished" , " object" );
70
65
iter->skip_container ();
71
66
iter.release ();
@@ -74,16 +69,17 @@ simdjson_really_inline object::~object() noexcept {
74
69
75
70
simdjson_really_inline simdjson_result<value> object::operator [](const std::string_view key) noexcept {
76
71
if (error) { return report_error (); }
72
+ if (!iter.is_alive ()) { return NO_SUCH_FIELD; }
77
73
78
74
// Unless this is the first field, we need to advance past the , and check for }
79
- if (has_next) {
80
- if (at_start) {
81
- at_start = false ;
82
- } else {
83
- if ((error = iter-> has_next_field (). get (has_next) )) { return report_error (); }
84
- }
75
+ bool has_value;
76
+ if (at_start) {
77
+ at_start = false ;
78
+ has_value = true ;
79
+ } else {
80
+ if ((error = iter-> has_next_field (). get (has_value) )) { return report_error (); }
85
81
}
86
- while (has_next ) {
82
+ while (has_value ) {
87
83
// Get the key
88
84
raw_json_string actual_key;
89
85
if ((error = iter->field_key ().get (actual_key) )) { return report_error (); };
@@ -96,21 +92,23 @@ simdjson_really_inline simdjson_result<value> object::operator[](const std::stri
96
92
}
97
93
logger::log_event (*iter, " no match" , key, -2 );
98
94
iter->skip (); // Skip the value entirely
99
- if ((error = iter->has_next_field ().get (has_next) )) { return report_error (); }
100
- if (!has_next) { iter.release (); }
95
+ if ((error = iter->has_next_field ().get (has_value) )) { return report_error (); }
101
96
}
102
97
103
98
// If the loop ended, we're out of fields to look at.
99
+ iter.release ();
104
100
return NO_SUCH_FIELD;
105
101
}
106
102
107
103
simdjson_really_inline simdjson_result<object> object::start (json_iterator_ref &&iter) noexcept {
108
104
bool has_value;
109
105
SIMDJSON_TRY ( iter->start_object ().get (has_value) );
110
- return object (std::forward<json_iterator_ref>(iter), has_value);
106
+ if (!has_value) { iter.release (); }
107
+ return object (std::forward<json_iterator_ref>(iter));
111
108
}
112
109
simdjson_really_inline object object::started (json_iterator_ref &&iter) noexcept {
113
- return object (std::forward<json_iterator_ref>(iter), iter->started_object ());
110
+ if (!iter->started_object ()) { iter.release (); }
111
+ return object (std::forward<json_iterator_ref>(iter));
114
112
}
115
113
simdjson_really_inline object::iterator object::begin () noexcept {
116
114
return *this ;
@@ -121,7 +119,6 @@ simdjson_really_inline object::iterator object::end() noexcept {
121
119
122
120
simdjson_really_inline error_code object::report_error () noexcept {
123
121
SIMDJSON_ASSUME (error);
124
- has_next = false ;
125
122
iter.release ();
126
123
return error;
127
124
}
@@ -138,19 +135,20 @@ simdjson_really_inline object::iterator &object::iterator::operator=(const objec
138
135
139
136
simdjson_really_inline simdjson_result<field> object::iterator::operator *() noexcept {
140
137
if (o->error ) { return o->report_error (); }
141
- if (o->at_start ) { o->at_start = false ; }
142
138
return field::start (o->iter .borrow ());
143
139
}
144
- simdjson_really_inline bool object::iterator::operator ==(const object::iterator &) noexcept {
145
- return !o-> has_next ;
140
+ simdjson_really_inline bool object::iterator::operator ==(const object::iterator &other ) noexcept {
141
+ return !(* this != other) ;
146
142
}
147
143
simdjson_really_inline bool object::iterator::operator !=(const object::iterator &) noexcept {
148
- return o->has_next ;
144
+ return o->iter . is_alive () ;
149
145
}
150
146
simdjson_really_inline object::iterator &object::iterator::operator ++() noexcept {
151
147
if (o->error ) { return *this ; }
152
- o->error = o->iter ->has_next_field ().get (o->has_next ); // If there's an error, has_next stays true.
153
- if (!o->has_next ) { o->iter .release (); }
148
+ o->at_start = false ;
149
+ bool has_value;
150
+ o->error = o->iter ->has_next_field ().get (has_value);
151
+ if (!(o->error || has_value)) { o->iter .release (); }
154
152
return *this ;
155
153
}
156
154
0 commit comments