diff --git a/benchmark/distinctuserid/ondemand.h b/benchmark/distinctuserid/ondemand.h index 933e630f..fd396340 100644 --- a/benchmark/distinctuserid/ondemand.h +++ b/benchmark/distinctuserid/ondemand.h @@ -33,15 +33,15 @@ simdjson_really_inline bool OnDemand::Run(const padded_string &json) { ids.clear(); // Walk the document, parsing as we go auto doc = parser.iterate(json); - for (ondemand::object tweet : doc["statuses"]) { + for (ondemand::object tweet : doc.find_field("statuses")) { // We believe that all statuses have a matching // user, and we are willing to throw when they do not. - ids.push_back(tweet["user"]["id"]); + ids.push_back(tweet.find_field("user").find_field("id")); // Not all tweets have a "retweeted_status", but when they do // we want to go and find the user within. - auto retweet = tweet["retweeted_status"]; + auto retweet = tweet.find_field("retweeted_status"); if(!retweet.error()) { - ids.push_back(retweet["user"]["id"]); + ids.push_back(retweet.find_field("user").find_field("id")); } } remove_duplicates(ids); diff --git a/benchmark/find_tweet/ondemand.h b/benchmark/find_tweet/ondemand.h index 0f8576c0..92e72dc2 100644 --- a/benchmark/find_tweet/ondemand.h +++ b/benchmark/find_tweet/ondemand.h @@ -33,9 +33,9 @@ simdjson_really_inline bool OnDemand::Run(const padded_string &json) { text = ""; // Walk the document, parsing as we go auto doc = parser.iterate(json); - for (ondemand::object tweet : doc["statuses"]) { - if (uint64_t(tweet["id"]) == TWEET_ID) { - text = tweet["text"]; + for (ondemand::object tweet : doc.find_field("statuses")) { + if (uint64_t(tweet.find_field("id")) == TWEET_ID) { + text = tweet.find_field("text"); return true; } } diff --git a/benchmark/kostya/ondemand.h b/benchmark/kostya/ondemand.h index 369ffedb..1da40120 100644 --- a/benchmark/kostya/ondemand.h +++ b/benchmark/kostya/ondemand.h @@ -27,8 +27,8 @@ simdjson_really_inline bool OnDemand::Run(const padded_string &json) { using std::endl; auto doc = parser.iterate(json); - for (ondemand::object coord : doc["coordinates"]) { - container.emplace_back(my_point{coord["x"], coord["y"], coord["z"]}); + for (ondemand::object coord : doc.find_field("coordinates")) { + container.emplace_back(my_point{coord.find_field("x"), coord.find_field("y"), coord.find_field("z")}); } return true; @@ -56,10 +56,10 @@ simdjson_really_inline bool OnDemand::Run(const padded_string &json) { count = 0; auto doc = parser.iterate(json); - for (ondemand::object coord : doc["coordinates"]) { - sum.x += double(coord["x"]); - sum.y += double(coord["y"]); - sum.z += double(coord["z"]); + for (ondemand::object coord : doc.find_field("coordinates")) { + sum.x += double(coord.find_field("x")); + sum.y += double(coord.find_field("y")); + sum.z += double(coord.find_field("z")); count++; } diff --git a/benchmark/largerandom/ondemand.h b/benchmark/largerandom/ondemand.h index 42c4a9b9..4151e311 100644 --- a/benchmark/largerandom/ondemand.h +++ b/benchmark/largerandom/ondemand.h @@ -25,7 +25,7 @@ simdjson_really_inline bool OnDemand::Run(const padded_string &json) { auto doc = parser.iterate(json); for (ondemand::object coord : doc) { - container.emplace_back(my_point{coord["x"], coord["y"], coord["z"]}); + container.emplace_back(my_point{coord.find_field("x"), coord.find_field("y"), coord.find_field("z")}); } return true; @@ -54,9 +54,9 @@ simdjson_really_inline bool OnDemand::Run(const padded_string &json) { auto doc = parser.iterate(json); for (ondemand::object coord : doc.get_array()) { - sum.x += double(coord["x"]); - sum.y += double(coord["y"]); - sum.z += double(coord["z"]); + sum.x += double(coord.find_field("x")); + sum.y += double(coord.find_field("y")); + sum.z += double(coord.find_field("z")); count++; } diff --git a/benchmark/partial_tweets/ondemand.h b/benchmark/partial_tweets/ondemand.h index 8ba2079b..def6e832 100644 --- a/benchmark/partial_tweets/ondemand.h +++ b/benchmark/partial_tweets/ondemand.h @@ -32,7 +32,7 @@ private: } simdjson_really_inline twitter_user read_user(ondemand::object user) { - return { user["id"], user["screen_name"] }; + return { user.find_field("id"), user.find_field("screen_name") }; } static inline bool displayed_implementation = false; @@ -43,15 +43,15 @@ simdjson_really_inline bool OnDemand::Run(const padded_string &json) { // Walk the document, parsing the tweets as we go auto doc = parser.iterate(json); - for (ondemand::object tweet : doc["statuses"]) { + for (ondemand::object tweet : doc.find_field("statuses")) { tweets.emplace_back(partial_tweets::tweet{ - tweet["created_at"], - tweet["id"], - tweet["text"], - nullable_int(tweet["in_reply_to_status_id"]), - read_user(tweet["user"]), - tweet["retweet_count"], - tweet["favorite_count"] + tweet.find_field("created_at"), + tweet.find_field("id"), + tweet.find_field("text"), + nullable_int(tweet.find_field("in_reply_to_status_id")), + read_user(tweet.find_field("user")), + tweet.find_field("retweet_count"), + tweet.find_field("favorite_count") }); } return true; diff --git a/include/simdjson/generic/ondemand/object-inl.h b/include/simdjson/generic/ondemand/object-inl.h index 9dcb0324..45a46dc9 100644 --- a/include/simdjson/generic/ondemand/object-inl.h +++ b/include/simdjson/generic/ondemand/object-inl.h @@ -18,7 +18,7 @@ simdjson_really_inline simdjson_result object::operator[](const std::stri return find_field_unordered(key); } simdjson_really_inline simdjson_result object::operator[](const std::string_view key) && noexcept { - return find_field_unordered(key); + return std::forward(*this).find_field_unordered(key); } simdjson_really_inline simdjson_result object::find_field(const std::string_view key) & noexcept { bool has_value;