Skip to content

Commit

Permalink
[Cleanup] Avoid std::make_pair
Browse files Browse the repository at this point in the history
  • Loading branch information
yashykt committed Jan 30, 2025
1 parent 9a9e90a commit 691fb0a
Show file tree
Hide file tree
Showing 29 changed files with 68 additions and 73 deletions.
28 changes: 13 additions & 15 deletions src/compiler/python_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ using grpc::protobuf::FileDescriptor;
using grpc::protobuf::compiler::GeneratorContext;
using grpc::protobuf::io::CodedOutputStream;
using grpc::protobuf::io::ZeroCopyOutputStream;
using std::make_pair;
using std::map;
using std::pair;
using std::replace;
Expand Down Expand Up @@ -234,11 +233,11 @@ bool PrivateGenerator::PrintBetaServerFactory(
return false;
}
method_implementation_constructors.insert(
make_pair(method->name(), method_implementation_constructor));
pair(method->name(), method_implementation_constructor));
input_message_modules_and_classes.insert(
make_pair(method->name(), input_message_module_and_class));
pair(method->name(), input_message_module_and_class));
output_message_modules_and_classes.insert(
make_pair(method->name(), output_message_module_and_class));
pair(method->name(), output_message_module_and_class));
}
StringMap method_dict;
method_dict["PackageQualifiedServiceName"] = package_qualified_service_name;
Expand Down Expand Up @@ -341,12 +340,11 @@ bool PrivateGenerator::PrintBetaStubFactory(
config.prefixes_to_filter)) {
return false;
}
method_cardinalities.insert(
make_pair(method->name(), method_cardinality));
method_cardinalities.insert(pair(method->name(), method_cardinality));
input_message_modules_and_classes.insert(
make_pair(method->name(), input_message_module_and_class));
pair(method->name(), input_message_module_and_class));
output_message_modules_and_classes.insert(
make_pair(method->name(), output_message_module_and_class));
pair(method->name(), output_message_module_and_class));
}
StringMap method_dict;
method_dict["PackageQualifiedServiceName"] = package_qualified_service_name;
Expand Down Expand Up @@ -838,10 +836,10 @@ pair<bool, std::string> PrivateGenerator::GetGrpcServices() {
"Client and server classes corresponding to protobuf-defined "
"services.\"\"\"\n");
if (!PrintPreamble(out.get())) {
return make_pair(false, "");
return pair(false, "");
}
if (!PrintGAServices(out.get())) {
return make_pair(false, "");
return pair(false, "");
}
} else {
out->Print("try:\n");
Expand All @@ -851,16 +849,16 @@ pair<bool, std::string> PrivateGenerator::GetGrpcServices() {
"# THESE ELEMENTS WILL BE DEPRECATED.\n"
"# Please use the generated *_pb2_grpc.py files instead.\n");
if (!PrintPreamble(out.get())) {
return make_pair(false, "");
return pair(false, "");
}
if (!PrintBetaPreamble(out.get())) {
return make_pair(false, "");
return pair(false, "");
}
if (!PrintGAServices(out.get())) {
return make_pair(false, "");
return pair(false, "");
}
if (!PrintBetaServices(out.get())) {
return make_pair(false, "");
return pair(false, "");
}
}
out->Print("except ImportError:\n");
Expand All @@ -870,7 +868,7 @@ pair<bool, std::string> PrivateGenerator::GetGrpcServices() {
}
}
}
return make_pair(true, std::move(output));
return pair(true, std::move(output));
}

} // namespace
Expand Down
4 changes: 2 additions & 2 deletions src/core/channelz/channelz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ ServerNode::~ServerNode() {}

void ServerNode::AddChildSocket(RefCountedPtr<SocketNode> node) {
MutexLock lock(&child_mu_);
child_sockets_.insert(std::make_pair(node->uuid(), std::move(node)));
child_sockets_.insert(std::pair(node->uuid(), std::move(node)));
}

void ServerNode::RemoveChildSocket(intptr_t child_uuid) {
Expand All @@ -344,7 +344,7 @@ void ServerNode::RemoveChildSocket(intptr_t child_uuid) {

void ServerNode::AddChildListenSocket(RefCountedPtr<ListenSocketNode> node) {
MutexLock lock(&child_mu_);
child_listen_sockets_.insert(std::make_pair(node->uuid(), std::move(node)));
child_listen_sockets_.insert(std::pair(node->uuid(), std::move(node)));
}

void ServerNode::RemoveChildListenSocket(intptr_t child_uuid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ int grpc_server_add_chaotic_good_port(grpc_server* server, const char* addr) {
auto bind_result = listener->Bind(ee_addr);
if (!bind_result.ok()) {
error_list.push_back(
std::make_pair(std::move(addr_str), bind_result.status()));
std::pair(std::move(addr_str), bind_result.status()));
continue;
}
if (port_num == 0) {
Expand Down
3 changes: 1 addition & 2 deletions src/core/ext/transport/inproc/inproc_transport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ MakeInProcessTransportPair(const ChannelArgs& server_channel_args) {
auto server_transport =
MakeOrphanable<InprocServerTransport>(server_channel_args);
auto client_transport = server_transport->MakeClientTransport();
return std::make_pair(std::move(client_transport),
std::move(server_transport));
return std::pair(std::move(client_transport), std::move(server_transport));
}

} // namespace grpc_core
Expand Down
4 changes: 2 additions & 2 deletions src/core/filter/blackboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ namespace grpc_core {

RefCountedPtr<Blackboard::Entry> Blackboard::Get(UniqueTypeName type,
const std::string& key) const {
auto it = map_.find(std::make_pair(type, key));
auto it = map_.find(std::pair(type, key));
if (it == map_.end()) return nullptr;
return it->second;
}

void Blackboard::Set(UniqueTypeName type, const std::string& key,
RefCountedPtr<Entry> entry) {
map_[std::make_pair(type, key)] = std::move(entry);
map_[std::pair(type, key)] = std::move(entry);
}

} // namespace grpc_core
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ CelAuthorizationEngine::CelAuthorizationEngine(
google_api_expr_v1alpha1_Expr_parse(serialized, serial_len,
arena_.ptr());
if (envoy_config_rbac_v3_RBAC_action(rbac_policy) == kAllow) {
allow_if_matched_.insert(std::make_pair(policy_name, parsed_condition));
allow_if_matched_.insert(std::pair(policy_name, parsed_condition));
} else {
deny_if_matched_.insert(std::make_pair(policy_name, parsed_condition));
deny_if_matched_.insert(std::pair(policy_name, parsed_condition));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/lib/surface/channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ Channel::Channel(std::string target, const ChannelArgs& channel_args)
Channel::RegisteredCall* Channel::RegisterCall(const char* method,
const char* host) {
MutexLock lock(&mu_);
auto key = std::make_pair(std::string(host != nullptr ? host : ""),
std::string(method != nullptr ? method : ""));
auto key = std::pair(std::string(host != nullptr ? host : ""),
std::string(method != nullptr ? method : ""));
auto rc_posn = registration_table_.find(key);
if (rc_posn != registration_table_.end()) {
return &rc_posn->second;
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ Server::RegisteredMethod* Server::RegisterMethod(
LOG(ERROR) << "grpc_server_register_method method string cannot be NULL";
return nullptr;
}
auto key = std::make_pair(host ? host : "", method);
auto key = std::pair(host ? host : "", method);
if (registered_methods_.find(key) != registered_methods_.end()) {
LOG(ERROR) << "duplicate registration for " << method << "@"
<< (host ? host : "*");
Expand Down Expand Up @@ -1697,12 +1697,12 @@ Server::RegisteredMethod* Server::GetRegisteredMethod(
const absl::string_view& host, const absl::string_view& path) {
if (registered_methods_.empty()) return nullptr;
// check for an exact match with host
auto it = registered_methods_.find(std::make_pair(host, path));
auto it = registered_methods_.find(std::pair(host, path));
if (it != registered_methods_.end()) {
return it->second.get();
}
// check for wildcard method definition (no host set)
it = registered_methods_.find(std::make_pair("", path));
it = registered_methods_.find(std::pair("", path));
if (it != registered_methods_.end()) {
return it->second.get();
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/util/time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ GPR_ATTRIBUTE_NOINLINE std::pair<int64_t, gpr_cycle_counter> InitTime() {
g_process_epoch_cycles.store(process_epoch_cycles,
std::memory_order_relaxed);
}
return std::make_pair(process_epoch_seconds, process_epoch_cycles);
return std::pair(process_epoch_seconds, process_epoch_cycles);
}

gpr_timespec StartTime() {
Expand Down
8 changes: 4 additions & 4 deletions src/core/xds/xds_client/lrs_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ RefCountedPtr<LrsClient::ClusterDropStats> LrsClient::AddClusterDropStats(
std::shared_ptr<const XdsBootstrap::XdsServer> lrs_server,
absl::string_view cluster_name, absl::string_view eds_service_name) {
auto key =
std::make_pair(std::string(cluster_name), std::string(eds_service_name));
std::pair(std::string(cluster_name), std::string(eds_service_name));
RefCountedPtr<ClusterDropStats> cluster_drop_stats;
{
MutexLock lock(&mu_);
Expand Down Expand Up @@ -856,7 +856,7 @@ void LrsClient::RemoveClusterDropStats(
if (server_it == load_report_map_.end()) return;
auto& server = server_it->second;
auto load_report_it = server.load_report_map.find(
std::make_pair(std::string(cluster_name), std::string(eds_service_name)));
std::pair(std::string(cluster_name), std::string(eds_service_name)));
if (load_report_it == server.load_report_map.end()) return;
LoadReportState& load_report_state = load_report_it->second;
if (load_report_state.drop_stats == cluster_drop_stats) {
Expand All @@ -875,7 +875,7 @@ LrsClient::AddClusterLocalityStats(
RefCountedPtr<XdsLocalityName> locality,
RefCountedPtr<const BackendMetricPropagation> backend_metric_propagation) {
auto key =
std::make_pair(std::string(cluster_name), std::string(eds_service_name));
std::pair(std::string(cluster_name), std::string(eds_service_name));
RefCountedPtr<ClusterLocalityStats> cluster_locality_stats;
{
MutexLock lock(&mu_);
Expand Down Expand Up @@ -929,7 +929,7 @@ void LrsClient::RemoveClusterLocalityStats(
if (server_it == load_report_map_.end()) return;
auto& server = server_it->second;
auto load_report_it = server.load_report_map.find(
std::make_pair(std::string(cluster_name), std::string(eds_service_name)));
std::pair(std::string(cluster_name), std::string(eds_service_name)));
if (load_report_it == server.load_report_map.end()) return;
LoadReportState& load_report_state = load_report_it->second;
auto locality_it = load_report_state.locality_stats.find(locality);
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/client/client_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ std::unique_ptr<ClientContext> ClientContext::FromCallbackServerContext(

void ClientContext::AddMetadata(const std::string& meta_key,
const std::string& meta_value) {
send_initial_metadata_.insert(std::make_pair(meta_key, meta_value));
send_initial_metadata_.insert(std::pair(meta_key, meta_value));
}

void ClientContext::set_call(grpc_call* call,
Expand Down
7 changes: 3 additions & 4 deletions src/cpp/ext/csm/metadata_exchange.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,9 @@ NextFromAttributeList(absl::Span<const RemoteAttribute> attributes,
const size_t index = curr - start_index;
if (index >= attributes.size()) return std::nullopt;
const auto& attribute = attributes[index];
return std::make_pair(
attribute.otel_attribute,
GetStringValueFromUpbStruct(decoded_metadata,
attribute.metadata_attribute, arena));
return std::pair(attribute.otel_attribute,
GetStringValueFromUpbStruct(
decoded_metadata, attribute.metadata_attribute, arena));
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/server/load_reporter/get_cpu_stats_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ std::pair<uint64_t, uint64_t> GetCpuStatsImpl() {
fclose(fp);
busy = user + nice + system;
total = busy + idle;
return std::make_pair(busy, total);
return std::pair(busy, total);
}

} // namespace load_reporter
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/server/load_reporter/get_cpu_stats_macos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ std::pair<uint64_t, uint64_t> GetCpuStatsImpl() {
for (int i = 0; i < CPU_STATE_MAX; i++) total += cpuinfo.cpu_ticks[i];
busy = total - cpuinfo.cpu_ticks[CPU_STATE_IDLE];
}
return std::make_pair(busy, total);
return std::pair(busy, total);
}

} // namespace load_reporter
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/server/load_reporter/get_cpu_stats_unsupported.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ std::pair<uint64_t, uint64_t> GetCpuStatsImpl() {
uint64_t busy = 0, total = 0;
LOG(ERROR)
<< "Platforms other than Linux, Windows, and MacOS are not supported.";
return std::make_pair(busy, total);
return std::pair(busy, total);
}

} // namespace load_reporter
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/server/load_reporter/get_cpu_stats_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ std::pair<uint64_t, uint64_t> GetCpuStatsImpl() {
total = FiletimeToInt(kernel) + FiletimeToInt(user);
busy = total - FiletimeToInt(idle);
}
return std::make_pair(busy, total);
return std::pair(busy, total);
}

} // namespace load_reporter
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/server/secure_server_credentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ void AuthMetadataProcessorAsyncWrapper::InvokeProcessor(
grpc_process_auth_metadata_done_cb cb, void* user_data) {
AuthMetadataProcessor::InputMetadata metadata;
for (size_t i = 0; i < num_md; i++) {
metadata.insert(std::make_pair(StringRefFromSlice(&md[i].key),
StringRefFromSlice(&md[i].value)));
metadata.insert(std::pair(StringRefFromSlice(&md[i].key),
StringRefFromSlice(&md[i].value)));
}
SecureAuthContext ctx(context);
AuthMetadataProcessor::OutputMetadata consumed_metadata;
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/server/server_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,12 @@ internal::CompletionQueueTag* ServerContextBase::GetCompletionOpTag() {

void ServerContextBase::AddInitialMetadata(const std::string& key,
const std::string& value) {
initial_metadata_.insert(std::make_pair(key, value));
initial_metadata_.insert(std::pair(key, value));
}

void ServerContextBase::AddTrailingMetadata(const std::string& key,
const std::string& value) {
trailing_metadata_.insert(std::make_pair(key, value));
trailing_metadata_.insert(std::pair(key, value));
}

void ServerContextBase::TryCancel() const {
Expand Down
2 changes: 1 addition & 1 deletion test/core/event_engine/event_engine_test_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ absl::Status ConnectionManager::BindAndStartListener(
// Insert same listener pointer for all bind addresses after the listener
// has started successfully.
for (auto& addr : addrs) {
listeners_.insert(std::make_pair(addr, listener));
listeners_.insert(std::pair(addr, listener));
}
return absl::OkStatus();
}
Expand Down
2 changes: 1 addition & 1 deletion test/core/memory_usage/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ std::pair<MemStats, MemStats> run_test_loop(int iterations, int* call_idx) {
init_ping_pong_request(*call_idx + i + 1);
}

auto peak = std::make_pair(
auto peak = std::pair(
// client
MemStats::Snapshot(),
// server
Expand Down
2 changes: 1 addition & 1 deletion test/core/transport/chttp2/hpack_sync_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void FuzzOneInput(const hpack_sync_fuzzer::Msg& msg) {
encode_output.c_slice_at(i), i == (encode_output.Count() - 1),
absl::BitGenRef(proto_bit_src), /*call_tracer=*/nullptr);
if (!err.ok()) {
seen_errors.push_back(std::make_pair(i, err));
seen_errors.push_back(std::pair(i, err));
// If we get a connection error (i.e. not a stream error), stop parsing,
// return.
if (!IsStreamError(err)) return;
Expand Down
3 changes: 1 addition & 2 deletions test/core/xds/xds_client_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,7 @@ class XdsClientTest : public ::testing::Test {
uint64_t num_resources_valid,
uint64_t num_resources_invalid) override {
MutexLock lock(&mu_);
auto key =
std::make_pair(std::string(xds_server), std::string(resource_type));
auto key = std::pair(std::string(xds_server), std::string(resource_type));
if (num_resources_valid > 0) {
resource_updates_valid_[key] += num_resources_valid;
}
Expand Down
8 changes: 4 additions & 4 deletions test/cpp/end2end/client_interceptors_end2end_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class HijackingInterceptor : public experimental::Interceptor {
auto* map = methods->GetRecvTrailingMetadata();
// insert the metadata that we want
EXPECT_EQ(map->size(), 0);
map->insert(std::make_pair("testkey", "testvalue"));
map->insert(std::pair("testkey", "testvalue"));
auto* status = methods->GetRecvStatus();
*status = Status(StatusCode::OK, "");
}
Expand Down Expand Up @@ -272,7 +272,7 @@ class HijackingInterceptorMakesAnotherCall : public experimental::Interceptor {
auto* map = methods->GetRecvTrailingMetadata();
// insert the metadata that we want
EXPECT_EQ(map->size(), 0);
map->insert(std::make_pair("testkey", "testvalue"));
map->insert(std::pair("testkey", "testvalue"));
auto* status = methods->GetRecvStatus();
*status = Status(StatusCode::OK, "");
}
Expand Down Expand Up @@ -353,7 +353,7 @@ class BidiStreamingRpcHijackingInterceptor : public experimental::Interceptor {
auto* map = methods->GetRecvTrailingMetadata();
// insert the metadata that we want
EXPECT_EQ(map->size(), 0);
map->insert(std::make_pair("testkey", "testvalue"));
map->insert(std::pair("testkey", "testvalue"));
auto* status = methods->GetRecvStatus();
*status = Status(StatusCode::OK, "");
}
Expand Down Expand Up @@ -497,7 +497,7 @@ class ServerStreamingRpcHijackingInterceptor
auto* map = methods->GetRecvTrailingMetadata();
// insert the metadata that we want
EXPECT_EQ(map->size(), 0);
map->insert(std::make_pair("testkey", "testvalue"));
map->insert(std::pair("testkey", "testvalue"));
auto* status = methods->GetRecvStatus();
*status = Status(StatusCode::OK, "");
}
Expand Down
Loading

0 comments on commit 691fb0a

Please sign in to comment.