8
8
SIMDJSON_TARGET_HASWELL
9
9
10
10
namespace twitter {
11
+ namespace {
11
12
12
13
using namespace simdjson ;
13
14
using namespace haswell ;
14
15
using namespace haswell ::stage2;
15
16
16
17
struct sax_tweet_reader_visitor {
17
18
public:
18
- sax_tweet_reader_visitor (std::vector<tweet> &_tweets , uint8_t *string_buf);
19
+ simdjson_really_inline sax_tweet_reader_visitor (std::vector<tweet> &tweets , uint8_t *string_buf);
19
20
20
21
simdjson_really_inline error_code visit_document_start (json_iterator &iter);
21
22
simdjson_really_inline error_code visit_object_start (json_iterator &iter);
@@ -68,8 +69,8 @@ struct sax_tweet_reader_visitor {
68
69
field_type type{field_type::any};
69
70
};
70
71
71
- containers container{containers::document};
72
72
std::vector<tweet> &tweets;
73
+ containers container{containers::document};
73
74
uint8_t *current_string_buf_loc;
74
75
const uint8_t *current_key{};
75
76
@@ -94,9 +95,9 @@ struct sax_tweet_reader_visitor {
94
95
static field_lookup fields;
95
96
}; // sax_tweet_reader_visitor
96
97
97
- sax_tweet_reader_visitor::sax_tweet_reader_visitor (std::vector<tweet> &_tweets, uint8_t *string_buf )
98
+ simdjson_really_inline sax_tweet_reader_visitor::sax_tweet_reader_visitor (std::vector<tweet> &_tweets, uint8_t *_string_buf )
98
99
: tweets{_tweets},
99
- current_string_buf_loc{string_buf } {
100
+ current_string_buf_loc{_string_buf } {
100
101
}
101
102
102
103
simdjson_really_inline error_code sax_tweet_reader_visitor::visit_document_start (json_iterator &iter) {
@@ -112,6 +113,7 @@ simdjson_really_inline error_code sax_tweet_reader_visitor::visit_array_start(js
112
113
switch (fields.get (current_key, container).type ) {
113
114
case field_type::array: // { "statuses": [
114
115
start_container (iter);
116
+ current_key = nullptr ;
115
117
return SUCCESS;
116
118
case field_type::any:
117
119
return SUCCESS;
@@ -190,6 +192,7 @@ simdjson_really_inline error_code sax_tweet_reader_visitor::visit_primitive(json
190
192
iter.log_error (" unexpected primitive" );
191
193
return INCORRECT_TYPE;
192
194
}
195
+ current_key = nullptr ;
193
196
}
194
197
195
198
// If it's not a field, it's a child of an array.
@@ -202,16 +205,17 @@ simdjson_really_inline error_code sax_tweet_reader_visitor::visit_array_end(json
202
205
return SUCCESS;
203
206
}
204
207
simdjson_really_inline error_code sax_tweet_reader_visitor::visit_object_end (json_iterator &iter) {
208
+ current_key = nullptr ;
205
209
if (in_container (iter)) { end_container (iter); }
206
210
return SUCCESS;
207
211
}
208
212
209
- simdjson_really_inline error_code sax_tweet_reader_visitor::visit_document_end (json_iterator &iter) {
210
- iter.log_end_value (" document" );
213
+ simdjson_really_inline error_code sax_tweet_reader_visitor::visit_document_end (json_iterator &) {
211
214
return SUCCESS;
212
215
}
213
216
214
217
simdjson_really_inline error_code sax_tweet_reader_visitor::visit_empty_array (json_iterator &) {
218
+ current_key = nullptr ;
215
219
return SUCCESS;
216
220
}
217
221
simdjson_really_inline error_code sax_tweet_reader_visitor::visit_empty_object (json_iterator &) {
@@ -233,16 +237,15 @@ simdjson_really_inline bool sax_tweet_reader_visitor::in_container_child(json_it
233
237
simdjson_really_inline void sax_tweet_reader_visitor::start_container (json_iterator &iter) {
234
238
SIMDJSON_ASSUME (iter.depth <= MAX_SUPPORTED_DEPTH); // Asserts in debug mode
235
239
container = containers (iter.depth );
240
+ if (logger::LOG_ENABLED) { iter.log_value (STATE_NAMES[iter.depth ]); }
236
241
if (container == containers::tweet) { tweets.push_back ({}); }
237
- if (logger::LOG_ENABLED) { iter.log_start_value (STATE_NAMES[iter.depth ]); }
238
242
}
239
- simdjson_really_inline void sax_tweet_reader_visitor::end_container (json_iterator &iter) {
240
- if (logger::LOG_ENABLED) { iter.log_end_value (STATE_NAMES[int (container)]); }
243
+ simdjson_really_inline void sax_tweet_reader_visitor::end_container (json_iterator &) {
241
244
container = containers (int (container) - 1 );
242
245
}
243
246
simdjson_really_inline error_code sax_tweet_reader_visitor::parse_nullable_unsigned (json_iterator &iter, const uint8_t *value, const field &f) {
244
247
iter.log_value (f.key );
245
- auto i = reinterpret_cast <uint64_t *>(reinterpret_cast <char *>(&tweets.back () + f.offset ) );
248
+ auto i = reinterpret_cast <uint64_t *>(reinterpret_cast <char *>(&tweets.back ()) + f.offset );
246
249
if (auto error = numberparsing::parse_unsigned (value).get (*i)) {
247
250
// If number parsing failed, check if it's null before returning the error
248
251
if (!atomparsing::is_valid_null_atom (value)) { iter.log_error (" expected number or null" ); return error; }
@@ -252,12 +255,12 @@ simdjson_really_inline error_code sax_tweet_reader_visitor::parse_nullable_unsig
252
255
}
253
256
simdjson_really_inline error_code sax_tweet_reader_visitor::parse_unsigned (json_iterator &iter, const uint8_t *value, const field &f) {
254
257
iter.log_value (f.key );
255
- auto i = reinterpret_cast <uint64_t *>(reinterpret_cast <char *>(&tweets.back () + f.offset ) );
258
+ auto i = reinterpret_cast <uint64_t *>(reinterpret_cast <char *>(&tweets.back ()) + f.offset );
256
259
return numberparsing::parse_unsigned (value).get (*i);
257
260
}
258
261
simdjson_really_inline error_code sax_tweet_reader_visitor::parse_string (json_iterator &iter, const uint8_t *value, const field &f) {
259
262
iter.log_value (f.key );
260
- auto s = reinterpret_cast <std::string_view *>(reinterpret_cast <char *>(&tweets.back () + f.offset ) );
263
+ auto s = reinterpret_cast <std::string_view *>(reinterpret_cast <char *>(&tweets.back ()) + f.offset );
261
264
return stringparsing::parse_string_to_buffer (value, current_string_buf_loc, *s);
262
265
}
263
266
@@ -513,6 +516,7 @@ sax_tweet_reader_visitor::field_lookup::field_lookup() {
513
516
// }
514
517
// }
515
518
519
+ } // unnamed namespace
516
520
} // namespace twitter
517
521
518
522
SIMDJSON_UNTARGET_REGION
0 commit comments