Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions google/cloud/bigtable/bound_query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ google::bigtable::v2::ExecuteQueryRequest BoundQuery::ToRequestProto() const {

google::protobuf::Map<std::string, google::bigtable::v2::Value> parameters;
for (auto const& kv : parameters_) {
parameters[kv.first] =
bigtable_internal::ValueInternals::ToProto(kv.second).second;
auto type_value = bigtable_internal::ValueInternals::ToProto(kv.second);
google::bigtable::v2::Value v = std::move(type_value.second);
*v.mutable_type() = std::move(type_value.first);
parameters[kv.first] = std::move(v);
Comment on lines +38 to +41

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This block can be simplified to avoid creating a temporary Value object and an extra move operation. You can directly operate on the map's value reference, which is slightly more efficient and readable.

    auto type_value = bigtable_internal::ValueInternals::ToProto(kv.second);
    auto& v = parameters[kv.first];
    v = std::move(type_value.second);
    *v.mutable_type() = std::move(type_value.first);

}
*result.mutable_params() = parameters;
*result.mutable_params() = std::move(parameters);
return result;
}

Expand Down
2 changes: 2 additions & 0 deletions google/cloud/bigtable/bound_query_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ TEST(BoundQuery, ToRequestProto) {
auto val1 = proto.params().find("val1")->second;
EXPECT_TRUE(val1.has_bool_value());
EXPECT_EQ(true, val1.bool_value());
EXPECT_TRUE(val1.type().has_bool_type());

// The second parameter is a double.
EXPECT_TRUE(proto.params().contains("val2"));
auto val2 = proto.params().find("val2")->second;
EXPECT_TRUE(val2.has_float_value());
EXPECT_EQ(2.0, val2.float_value());
EXPECT_TRUE(val2.type().has_float64_type());

// Cancel all pending operations, satisfying any remaining futures.
fake_cq_impl->SimulateCompletion(false);
Expand Down