@@ -18,17 +18,15 @@ static void numbers_scan(State& state) {
1818 dom::parser parser;
1919 dom::array arr;
2020 simdjson::error_code error;
21- parser.load (NUMBERS_JSON).get <dom::array>().tie (arr, error);
22- if (error) {
23- cerr << " could not read " << NUMBERS_JSON << " as an array" << endl;
21+ if (!parser.load (NUMBERS_JSON).get (arr, error)) {
22+ cerr << " could not read " << NUMBERS_JSON << " as an array: " << error << endl;
2423 return ;
2524 }
2625 for (UNUSED auto _ : state) {
2726 std::vector<double > container;
2827 for (auto e : arr) {
2928 double x;
30- e.get <double >().tie (x,error);
31- if (error) { cerr << " found a node that is not an number?" << endl; break ;}
29+ if (!e.get (x,error)) { cerr << " found a node that is not an number: " << error << endl; break ;}
3230 container.push_back (x);
3331 }
3432 benchmark::DoNotOptimize (container.data ());
@@ -42,9 +40,8 @@ static void numbers_size_scan(State& state) {
4240 dom::parser parser;
4341 dom::array arr;
4442 simdjson::error_code error;
45- parser.load (NUMBERS_JSON).get <dom::array>().tie (arr, error);
46- if (error) {
47- cerr << " could not read " << NUMBERS_JSON << " as an array" << endl;
43+ if (!parser.load (NUMBERS_JSON).get (arr, error)) {
44+ cerr << " could not read " << NUMBERS_JSON << " as an array: " << error << endl;
4845 return ;
4946 }
5047 for (UNUSED auto _ : state) {
@@ -53,8 +50,7 @@ static void numbers_size_scan(State& state) {
5350 size_t pos = 0 ;
5451 for (auto e : arr) {
5552 double x;
56- e.get <double >().tie (x,error);
57- if (error) { cerr << " found a node that is not an number?" << endl; break ;}
53+ if (!e.get (x,error)) { cerr << " found a node that is not an number: " << error << endl; break ;}
5854 container[pos++] = x;
5955 }
6056 if (pos != container.size ()) { cerr << " bad count" << endl; }
@@ -70,8 +66,7 @@ static void numbers_type_scan(State& state) {
7066 dom::parser parser;
7167 dom::array arr;
7268 simdjson::error_code error;
73- parser.load (NUMBERS_JSON).get <dom::array>().tie (arr, error);
74- if (error) {
69+ if (!parser.load (NUMBERS_JSON).get (arr, error)) {
7570 cerr << " could not read " << NUMBERS_JSON << " as an array" << endl;
7671 return ;
7772 }
@@ -83,7 +78,7 @@ static void numbers_type_scan(State& state) {
8378 cerr << " found a node that is not an number?" << endl; break ;
8479 }
8580 double x;
86- e.get < double >(). tie (x,error);
81+ e.get (x,error);
8782 container.push_back (x);
8883 }
8984 benchmark::DoNotOptimize (container.data ());
@@ -97,9 +92,8 @@ static void numbers_type_size_scan(State& state) {
9792 dom::parser parser;
9893 dom::array arr;
9994 simdjson::error_code error;
100- parser.load (NUMBERS_JSON).get <dom::array>().tie (arr, error);
101- if (error) {
102- cerr << " could not read " << NUMBERS_JSON << " as an array" << endl;
95+ if (!parser.load (NUMBERS_JSON).get (arr, error)) {
96+ cerr << " could not read " << NUMBERS_JSON << " as an array: " << error << endl;
10397 return ;
10498 }
10599 for (UNUSED auto _ : state) {
@@ -112,7 +106,7 @@ static void numbers_type_size_scan(State& state) {
112106 cerr << " found a node that is not an number?" << endl; break ;
113107 }
114108 double x;
115- e.get < double >(). tie (x,error);
109+ e.get (x,error);
116110 container[pos++] = x;
117111 }
118112 if (pos != container.size ()) { cerr << " bad count" << endl; }
@@ -129,16 +123,14 @@ static void numbers_load_scan(State& state) {
129123 simdjson::error_code error;
130124 for (UNUSED auto _ : state) {
131125 // this may hit the disk, but probably just once
132- parser.load (NUMBERS_JSON).get <dom::array>().tie (arr, error);
133- if (error) {
134- cerr << " could not read " << NUMBERS_JSON << " as an array" << endl;
126+ if (!parser.load (NUMBERS_JSON).get (arr, error)) {
127+ cerr << " could not read " << NUMBERS_JSON << " as an array: " << error << endl;
135128 break ;
136129 }
137130 std::vector<double > container;
138131 for (auto e : arr) {
139132 double x;
140- e.get <double >().tie (x,error);
141- if (error) { cerr << " found a node that is not an number?" << endl; break ;}
133+ if (!e.get (x,error)) { cerr << " found a node that is not an number: " << error << endl; break ;}
142134 container.push_back (x);
143135 }
144136 benchmark::DoNotOptimize (container.data ());
@@ -154,8 +146,7 @@ static void numbers_load_size_scan(State& state) {
154146 simdjson::error_code error;
155147 for (UNUSED auto _ : state) {
156148 // this may hit the disk, but probably just once
157- parser.load (NUMBERS_JSON).get <dom::array>().tie (arr, error);
158- if (error) {
149+ if (!parser.load (NUMBERS_JSON).get (arr, error)) {
159150 cerr << " could not read " << NUMBERS_JSON << " as an array" << endl;
160151 break ;
161152 }
@@ -164,8 +155,7 @@ static void numbers_load_size_scan(State& state) {
164155 size_t pos = 0 ;
165156 for (auto e : arr) {
166157 double x;
167- e.get <double >().tie (x,error);
168- if (error) { cerr << " found a node that is not an number?" << endl; break ;}
158+ if (!e.get (x,error)) { cerr << " found a node that is not an number?" << endl; break ;}
169159 container[pos++] = x;
170160 }
171161 if (pos != container.size ()) { cerr << " bad count" << endl; }
@@ -328,7 +318,7 @@ static void twitter_default_profile(State& state) {
328318 dom::element doc = parser.load (TWITTER_JSON);
329319 for (UNUSED auto _ : state) {
330320 set<string_view> default_users;
331- for (dom::object tweet : doc[" statuses" ]. get <dom::array>() ) {
321+ for (dom::object tweet : doc[" statuses" ]) {
332322 dom::object user = tweet[" user" ];
333323 if (user[" default_profile" ]) {
334324 default_users.insert (user[" screen_name" ]);
@@ -343,12 +333,13 @@ static void twitter_image_sizes(State& state) {
343333 // Count unique image sizes
344334 dom::parser parser;
345335 dom::element doc = parser.load (TWITTER_JSON);
336+ simdjson::error_code error;
346337 for (UNUSED auto _ : state) {
347338 set<tuple<uint64_t , uint64_t >> image_sizes;
348- for (dom::object tweet : doc[" statuses" ]. get <dom::array>() ) {
349- auto [ media, not_found] = tweet[ " entities " ][ " media " ] ;
350- if (!not_found ) {
351- for (dom::object image : media. get <dom::array>() ) {
339+ for (dom::object tweet : doc[" statuses" ]) {
340+ dom::array media;
341+ if (tweet[ " entities " ][ " media " ]. get (media, error) ) {
342+ for (dom::object image : media) {
352343 for (auto size : image[" sizes" ].get <dom::object>()) {
353344 image_sizes.insert ({ size.value [" w" ], size.value [" h" ] });
354345 }
@@ -365,11 +356,12 @@ BENCHMARK(twitter_image_sizes);
365356static void error_code_twitter_count (State& state) noexcept {
366357 // Prints the number of results in twitter.json
367358 dom::parser parser;
368- auto [doc, error1] = parser.load (TWITTER_JSON);
369- if (error1) { return ; }
359+ simdjson::error_code error;
360+ dom::element doc;
361+ if (!parser.load (TWITTER_JSON).get (doc, error)) { return ; }
370362 for (UNUSED auto _ : state) {
371- auto [ value, error] = doc[ " search_metadata " ][ " count " ]. get < uint64_t >() ;
372- if (error) { return ; }
363+ uint64_t value;
364+ if (!doc[ " search_metadata " ][ " count " ]. get (value, error) ) { return ; }
373365 if (value != 100 ) { return ; }
374366 }
375367}
@@ -378,21 +370,22 @@ BENCHMARK(error_code_twitter_count);
378370static void error_code_twitter_default_profile (State& state) noexcept {
379371 // Count unique users with a default profile.
380372 dom::parser parser;
381- auto [doc, error1] = parser.load (TWITTER_JSON);
382- if (error1) { std::cerr << error1 << std::endl; return ; }
373+ simdjson::error_code error;
374+ dom::element doc;
375+ if (!parser.load (TWITTER_JSON).get (doc, error)) { std::cerr << error << std::endl; return ; }
383376 for (UNUSED auto _ : state) {
384377 set<string_view> default_users;
385378
386- auto [tweets, error] = doc[ " statuses " ]. get < dom::array>() ;
387- if (error) { return ; }
379+ dom::array tweets ;
380+ if (!doc[ " statuses " ]. get (tweets, error) ) { return ; }
388381 for (dom::element tweet : tweets) {
389- auto [user, error2] = tweet[ " user " ]. get < dom::object>() ;
390- if (error2 ) { return ; }
391- auto [ default_profile, error3] = user[ " default_profile " ]. get < bool >() ;
392- if (error3 ) { return ; }
382+ dom::object user ;
383+ if (!tweet[ " user " ]. get (user, error) ) { return ; }
384+ bool default_profile;
385+ if (!user[ " default_profile " ]. get (default_profile, error) ) { return ; }
393386 if (default_profile) {
394- auto [screen_name, error4] = user[ " screen_name " ]. get < std::string_view>() ;
395- if (error4 ) { return ; }
387+ std::string_view screen_name ;
388+ if (!user[ " screen_name " ]. get (screen_name, error) ) { return ; }
396389 default_users.insert (screen_name);
397390 }
398391 }
@@ -406,8 +399,9 @@ SIMDJSON_PUSH_DISABLE_WARNINGS
406399SIMDJSON_DISABLE_DEPRECATED_WARNING
407400static void iterator_twitter_default_profile (State& state) {
408401 // Count unique users with a default profile.
409- auto [json, error1] = padded_string::load (TWITTER_JSON);
410- if (error1) { std::cerr << error1 << std::endl; return ; }
402+ simdjson::padded_string json;
403+ simdjson::error_code error;
404+ if (!padded_string::load (TWITTER_JSON).tie (json, error)) { std::cerr << error << std::endl; return ; }
411405 ParsedJson pj = build_parsed_json (json);
412406 for (UNUSED auto _ : state) {
413407 set<string_view> default_users;
@@ -447,22 +441,22 @@ BENCHMARK(iterator_twitter_default_profile);
447441static void error_code_twitter_image_sizes (State& state) noexcept {
448442 // Count unique image sizes
449443 dom::parser parser;
450- auto [doc, error1] = parser.load (TWITTER_JSON);
451- if (error1) { std::cerr << error1 << std::endl; return ; }
444+ simdjson::error_code error;
445+ dom::element doc;
446+ if (!parser.load (TWITTER_JSON).get (doc, error)) { std::cerr << error << std::endl; return ; }
452447 for (UNUSED auto _ : state) {
453448 set<tuple<uint64_t , uint64_t >> image_sizes;
454- auto [statuses, error] = doc[ " statuses " ]. get < dom::array>() ;
455- if (error) { return ; }
449+ dom::array statuses ;
450+ if (!doc[ " statuses " ]. get (statuses, error) ) { return ; }
456451 for (dom::element tweet : statuses) {
457- auto [images, not_found] = tweet[ " entities " ][ " media " ]. get < dom::array>() ;
458- if (!not_found ) {
452+ dom::array images ;
453+ if (tweet[ " entities " ][ " media " ]. get (images, error) ) {
459454 for (dom::element image : images) {
460- auto [sizes, error2] = image[ " sizes " ]. get < dom::object>() ;
461- if (error2 ) { return ; }
455+ dom::object sizes ;
456+ if (!image[ " sizes " ]. get (sizes, error) ) { return ; }
462457 for (auto size : sizes) {
463- auto [width, error3] = size.value [" w" ].get <uint64_t >();
464- auto [height, error4] = size.value [" h" ].get <uint64_t >();
465- if (error3 || error4) { return ; }
458+ uint64_t width, height;
459+ if (!size.value [" w" ].get (width, error) || !size.value [" h" ].get (height, error)) { return ; }
466460 image_sizes.insert ({ width, height });
467461 }
468462 }
@@ -477,8 +471,9 @@ SIMDJSON_PUSH_DISABLE_WARNINGS
477471SIMDJSON_DISABLE_DEPRECATED_WARNING
478472static void iterator_twitter_image_sizes (State& state) {
479473 // Count unique image sizes
480- auto [json, error1] = padded_string::load (TWITTER_JSON);
481- if (error1) { std::cerr << error1 << std::endl; return ; }
474+ simdjson::error_code error;
475+ padded_string json;
476+ if (!padded_string::load (TWITTER_JSON).tie (json, error)) { std::cerr << error << std::endl; return ; }
482477 ParsedJson pj = build_parsed_json (json);
483478 for (UNUSED auto _ : state) {
484479 set<tuple<uint64_t , uint64_t >> image_sizes;
@@ -536,10 +531,12 @@ BENCHMARK(iterator_twitter_image_sizes);
536531
537532static void print_json (State& state) noexcept {
538533 // Prints the number of results in twitter.json
539- auto [json, error1] = padded_string::load (TWITTER_JSON);
540- if (error1) { std::cerr << error1 << std::endl; return ; }
534+ simdjson::error_code error;
535+ padded_string json;
536+ if (!padded_string::load (TWITTER_JSON).tie (json, error)) { std::cerr << error << std::endl; return ; }
541537 dom::parser parser;
542- if (int error = json_parse (json, parser); error != SUCCESS) { cerr << error_message (error) << endl; return ; }
538+ int code = json_parse (json, parser);
539+ if (code) { cerr << error_message (code) << endl; return ; }
543540 for (UNUSED auto _ : state) {
544541 std::stringstream s;
545542 if (!parser.print_json (s)) { cerr << " print_json failed" << endl; return ; }
0 commit comments