@@ -33,94 +33,119 @@ simdjson_really_inline value value::start(json_iterator_ref &&iter) noexcept {
33
33
return { std::forward<json_iterator_ref>(iter), iter->advance () };
34
34
}
35
35
36
- simdjson_really_inline simdjson_result<array> value::get_array () noexcept {
36
+ simdjson_really_inline simdjson_result<array> value::get_array () && noexcept {
37
37
if (*json != ' [' ) {
38
38
log_error (" not an array" );
39
+ iter.release (); // Communicate that we have handled the value PERF TODO elided, right?
39
40
return INCORRECT_TYPE;
40
41
}
41
- return array::started (std::move (iter));
42
+ return array::started (std::forward<json_iterator_ref> (iter));
42
43
}
43
- simdjson_really_inline simdjson_result<object> value::get_object () noexcept {
44
+ simdjson_really_inline simdjson_result<object> value::get_object () && noexcept {
44
45
if (*json != ' {' ) {
45
46
log_error (" not an object" );
47
+ iter.release (); // Communicate that we have handled the value PERF TODO elided, right?
46
48
return INCORRECT_TYPE;
47
49
}
48
- return object::started (std::move (iter));
50
+ return object::started (std::forward<json_iterator_ref> (iter));
49
51
}
50
- simdjson_really_inline simdjson_result<raw_json_string> value::get_raw_json_string () noexcept {
52
+ simdjson_really_inline simdjson_result<raw_json_string> value::get_raw_json_string () && noexcept {
51
53
log_value (" string" );
52
- if (*json != ' "' ) { log_error (" not a string" ); return INCORRECT_TYPE; }
53
- auto result = raw_json_string{&json[1 ]};
54
54
iter.release (); // Communicate that we have handled the value PERF TODO elided, right?
55
- return result;
55
+ if (*json != ' "' ) { log_error (" not a string" ); return INCORRECT_TYPE; }
56
+ return raw_json_string{&json[1 ]};
56
57
}
57
- simdjson_really_inline simdjson_result<std::string_view> value::get_string () noexcept {
58
+ simdjson_really_inline simdjson_result<std::string_view> value::get_string () && noexcept {
58
59
log_value (" string" );
59
- if (*json != ' "' ) { log_error (" not a string" ); return INCORRECT_TYPE; }
60
+ if (*json != ' "' ) {
61
+ log_error (" not a string" );
62
+ iter.release (); // Communicate that we have handled the value PERF TODO elided, right?
63
+ return INCORRECT_TYPE;
64
+ }
60
65
auto result = raw_json_string{&json[1 ]}.unescape (iter->current_string_buf_loc );
61
66
iter.release (); // Communicate that we have handled the value PERF TODO elided, right?
62
67
return result;
63
68
}
64
- simdjson_really_inline simdjson_result<double > value::get_double () noexcept {
69
+ simdjson_really_inline simdjson_result<double > value::get_double () && noexcept {
65
70
log_value (" double" );
71
+ iter.release (); // Communicate that we have handled the value PERF TODO elided, right?
66
72
double result;
67
73
error_code error;
68
74
if ((error = stage2::numberparsing::parse_double (json).get (result))) { log_error (" not a double" ); return error; }
69
- iter.release (); // Communicate that we have handled the value PERF TODO elided, right?
70
75
return result;
71
76
}
72
- simdjson_really_inline simdjson_result<uint64_t > value::get_uint64 () noexcept {
77
+ simdjson_really_inline simdjson_result<uint64_t > value::get_uint64 () && noexcept {
73
78
log_value (" unsigned" );
79
+ iter.release (); // Communicate that we have handled the value PERF TODO elided, right?
74
80
uint64_t result;
75
81
error_code error;
76
82
if ((error = stage2::numberparsing::parse_unsigned (json).get (result))) { log_error (" not a unsigned integer" ); return error; }
77
- iter.release (); // Communicate that we have handled the value PERF TODO elided, right?
78
83
return result;
79
84
}
80
- simdjson_really_inline simdjson_result<int64_t > value::get_int64 () noexcept {
85
+ simdjson_really_inline simdjson_result<int64_t > value::get_int64 () && noexcept {
81
86
log_value (" integer" );
87
+ iter.release (); // Communicate that we have handled the value PERF TODO elided, right?
82
88
int64_t result;
83
89
error_code error;
84
90
if ((error = stage2::numberparsing::parse_integer (json).get (result))) { log_error (" not an integer" ); return error; }
85
- iter.release (); // Communicate that we have handled the value PERF TODO elided, right?
86
91
return result;
87
92
}
88
- simdjson_really_inline simdjson_result<bool > value::get_bool () noexcept {
93
+ simdjson_really_inline simdjson_result<bool > value::get_bool () && noexcept {
89
94
log_value (" bool" );
95
+ iter.release (); // Communicate that we have handled the value PERF TODO elided, right?
90
96
auto not_true = stage2::atomparsing::str4ncmp (json, " true" );
91
97
auto not_false = stage2::atomparsing::str4ncmp (json, " fals" ) | (json[4 ] ^ ' e' );
92
98
bool error = (not_true && not_false) || stage2::is_not_structural_or_whitespace (json[not_true ? 5 : 4 ]);
93
99
if (error) { log_error (" not a boolean" ); return INCORRECT_TYPE; }
94
- iter.release (); // Communicate that we have handled the value PERF TODO elided, right?
95
100
return simdjson_result<bool >(!not_true, error ? INCORRECT_TYPE : SUCCESS);
96
101
}
97
- simdjson_really_inline bool value::is_null () noexcept {
102
+ simdjson_really_inline bool value::is_null () & noexcept {
98
103
log_value (" null" );
104
+ // Since it's a *reference*, we may want to check something other than is_null() if it isn't null,
105
+ // so we don't release the iterator unless it is actually null
99
106
if (stage2::atomparsing::str4ncmp (json, " null" )) { return false ; }
100
107
iter.release (); // Communicate that we have handled the value PERF TODO elided, right?
101
108
return true ;
102
109
}
110
+ simdjson_really_inline bool value::is_null () && noexcept {
111
+ log_value (" null" );
112
+ iter.release (); // Communicate that we have handled the value PERF TODO elided, right?
113
+ if (stage2::atomparsing::str4ncmp (json, " null" )) { return false ; }
114
+ return true ;
115
+ }
103
116
104
117
#if SIMDJSON_EXCEPTIONS
105
- simdjson_really_inline value::operator array () noexcept (false ) { return get_array (); }
106
- simdjson_really_inline value::operator object () noexcept (false ) { return get_object (); }
107
- simdjson_really_inline value::operator uint64_t () noexcept (false ) { return get_uint64 (); }
108
- simdjson_really_inline value::operator int64_t () noexcept (false ) { return get_int64 (); }
109
- simdjson_really_inline value::operator double () noexcept (false ) { return get_double (); }
110
- simdjson_really_inline value::operator std::string_view () noexcept (false ) { return get_string (); }
111
- simdjson_really_inline value::operator raw_json_string () noexcept (false ) { return get_raw_json_string (); }
112
- simdjson_really_inline value::operator bool () noexcept (false ) { return get_bool (); }
118
+ simdjson_really_inline value::operator array () && noexcept (false ) {
119
+ return std::forward<value>(*this ).get_array ();
120
+ }
121
+ simdjson_really_inline value::operator object () && noexcept (false ) {
122
+ return std::forward<value>(*this ).get_object ();
123
+ }
124
+ simdjson_really_inline value::operator uint64_t () && noexcept (false ) {
125
+ return std::forward<value>(*this ).get_uint64 ();
126
+ }
127
+ simdjson_really_inline value::operator int64_t () && noexcept (false ) {
128
+ return std::forward<value>(*this ).get_int64 ();
129
+ }
130
+ simdjson_really_inline value::operator double () && noexcept (false ) {
131
+ return std::forward<value>(*this ).get_double ();
132
+ }
133
+ simdjson_really_inline value::operator std::string_view () && noexcept (false ) {
134
+ return std::forward<value>(*this ).get_string ();
135
+ }
136
+ simdjson_really_inline value::operator raw_json_string () && noexcept (false ) {
137
+ return std::forward<value>(*this ).get_raw_json_string ();
138
+ }
139
+ simdjson_really_inline value::operator bool () && noexcept (false ) {
140
+ return std::forward<value>(*this ).get_bool ();
141
+ }
113
142
#endif
114
143
115
- simdjson_really_inline simdjson_result<array::iterator> value::begin () noexcept { return get_array ().begin (); }
116
- simdjson_really_inline simdjson_result<array::iterator> value::end () noexcept { return {}; }
117
- // TODO this CANNOT be reused. Each time you try, it will get you a new object.
118
- // Probably make it move-only to avoid this issue.
119
- simdjson_really_inline simdjson_result<value> value::operator [](std::string_view key) noexcept {
120
- return get_object ()[key];
144
+ simdjson_really_inline simdjson_result<value> value::operator [](std::string_view key) && noexcept {
145
+ return std::forward<value>(*this ).get_object ()[key];
121
146
}
122
- simdjson_really_inline simdjson_result<value> value::operator [](const char *key) noexcept {
123
- return get_object ()[key];
147
+ simdjson_really_inline simdjson_result<value> value::operator [](const char *key) && noexcept {
148
+ return std::forward<value>(* this ). get_object ()[key];
124
149
}
125
150
126
151
simdjson_really_inline void value::log_value (const char *type) const noexcept {
@@ -163,90 +188,94 @@ simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>
163
188
164
189
simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array::iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::begin() noexcept {
165
190
if (error ()) { return error (); }
166
- return std::move (first. begin () );
191
+ return std::move (first). get_array (). begin ( );
167
192
}
168
193
simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array::iterator> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::end() noexcept {
169
194
if (error ()) { return error (); }
170
- return std::move (first. end ()) ;
195
+ return {} ;
171
196
}
172
197
simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator [](std::string_view key) noexcept {
173
198
if (error ()) { return error (); }
174
- return first[key];
199
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>( first) [key];
175
200
}
176
201
simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator [](const char *key) noexcept {
177
202
if (error ()) { return error (); }
178
- return first[key];
203
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>( first) [key];
179
204
}
180
205
181
- simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_array() noexcept {
206
+ simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::array> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_array() && noexcept {
182
207
if (error ()) { return error (); }
183
- return first.get_array ();
208
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>( first) .get_array ();
184
209
}
185
- simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_object() noexcept {
210
+ simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::object> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_object() && noexcept {
186
211
if (error ()) { return error (); }
187
- return first.get_object ();
212
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>( first) .get_object ();
188
213
}
189
- simdjson_really_inline simdjson_result<uint64_t > simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_uint64() noexcept {
214
+ simdjson_really_inline simdjson_result<uint64_t > simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_uint64() && noexcept {
190
215
if (error ()) { return error (); }
191
- return first.get_uint64 ();
216
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>( first) .get_uint64 ();
192
217
}
193
- simdjson_really_inline simdjson_result<int64_t > simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_int64() noexcept {
218
+ simdjson_really_inline simdjson_result<int64_t > simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_int64() && noexcept {
194
219
if (error ()) { return error (); }
195
- return first.get_int64 ();
220
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>( first) .get_int64 ();
196
221
}
197
- simdjson_really_inline simdjson_result<double > simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_double() noexcept {
222
+ simdjson_really_inline simdjson_result<double > simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_double() && noexcept {
198
223
if (error ()) { return error (); }
199
- return first.get_double ();
224
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>( first) .get_double ();
200
225
}
201
- simdjson_really_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_string() noexcept {
226
+ simdjson_really_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_string() && noexcept {
202
227
if (error ()) { return error (); }
203
- return first.get_string ();
228
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>( first) .get_string ();
204
229
}
205
- simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_raw_json_string() noexcept {
230
+ simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_raw_json_string() && noexcept {
206
231
if (error ()) { return error (); }
207
- return first.get_raw_json_string ();
232
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>( first) .get_raw_json_string ();
208
233
}
209
- simdjson_really_inline simdjson_result<bool > simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_bool() noexcept {
234
+ simdjson_really_inline simdjson_result<bool > simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_bool() && noexcept {
210
235
if (error ()) { return error (); }
211
- return first.get_bool ();
236
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>( first) .get_bool ();
212
237
}
213
- simdjson_really_inline bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_null() noexcept {
238
+ simdjson_really_inline bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_null() & noexcept {
214
239
if (error ()) { return false ; }
215
240
return first.is_null ();
216
241
}
242
+ simdjson_really_inline bool simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::is_null() && noexcept {
243
+ if (error ()) { return false ; }
244
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>(first).is_null ();
245
+ }
217
246
218
247
#if SIMDJSON_EXCEPTIONS
219
- simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::array () noexcept (false ) {
248
+ simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::array () && noexcept (false ) {
220
249
if (error ()) { throw simdjson_error (error ()); }
221
- return first;
250
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>( first) ;
222
251
}
223
- simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::object () noexcept (false ) {
252
+ simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::object () && noexcept (false ) {
224
253
if (error ()) { throw simdjson_error (error ()); }
225
- return first;
254
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>( first) ;
226
255
}
227
- simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator uint64_t () noexcept (false ) {
256
+ simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator uint64_t () && noexcept (false ) {
228
257
if (error ()) { throw simdjson_error (error ()); }
229
- return first;
258
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>( first) ;
230
259
}
231
- simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator int64_t () noexcept (false ) {
260
+ simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator int64_t () && noexcept (false ) {
232
261
if (error ()) { throw simdjson_error (error ()); }
233
- return first;
262
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>( first) ;
234
263
}
235
- simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator double () noexcept (false ) {
264
+ simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator double () && noexcept (false ) {
236
265
if (error ()) { throw simdjson_error (error ()); }
237
- return first;
266
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>( first) ;
238
267
}
239
- simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator std::string_view () noexcept (false ) {
268
+ simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator std::string_view () && noexcept (false ) {
240
269
if (error ()) { throw simdjson_error (error ()); }
241
- return first;
270
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>( first) ;
242
271
}
243
- simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string () noexcept (false ) {
272
+ simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string () && noexcept (false ) {
244
273
if (error ()) { throw simdjson_error (error ()); }
245
- return first;
274
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>( first) ;
246
275
}
247
- simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator bool () noexcept (false ) {
276
+ simdjson_really_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::operator bool () && noexcept (false ) {
248
277
if (error ()) { throw simdjson_error (error ()); }
249
- return first;
278
+ return std::forward<SIMDJSON_IMPLEMENTATION::ondemand::value>( first) ;
250
279
}
251
280
#endif
252
281
0 commit comments