From 3de8f0b849fcfc1206451e0840c9e1ec9041510f Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Wed, 6 Nov 2019 11:58:54 -0800 Subject: [PATCH] Replaced grpc_core::Map with std::map --- .../ext/filters/client_channel/backend_metric.cc | 4 ++-- .../ext/filters/client_channel/client_channel.cc | 10 +++++----- src/core/ext/filters/client_channel/lb_policy.h | 5 +++-- .../client_channel/lb_policy/grpclb/grpclb.cc | 3 +-- .../filters/client_channel/lb_policy/xds/xds.cc | 4 ++-- src/core/ext/filters/client_channel/subchannel.h | 6 +++--- src/core/ext/filters/client_channel/xds/xds_api.cc | 6 +++--- src/core/ext/filters/client_channel/xds/xds_api.h | 2 +- .../filters/client_channel/xds/xds_bootstrap.cc | 2 +- .../ext/filters/client_channel/xds/xds_bootstrap.h | 7 ++++--- .../ext/filters/client_channel/xds/xds_client.h | 4 ++-- .../filters/client_channel/xds/xds_client_stats.h | 14 +++++++------- src/core/lib/channel/channelz.h | 8 ++++---- src/core/lib/channel/channelz_registry.h | 2 +- src/core/lib/gprpp/map.h | 8 -------- src/core/lib/security/credentials/credentials.cc | 12 ++++++------ src/core/lib/security/credentials/credentials.h | 6 +++--- src/core/lib/transport/connectivity_state.h | 4 ++-- 18 files changed, 50 insertions(+), 57 deletions(-) diff --git a/src/core/ext/filters/client_channel/backend_metric.cc b/src/core/ext/filters/client_channel/backend_metric.cc index 0d6aa2f6e2c..b36614f5b80 100644 --- a/src/core/ext/filters/client_channel/backend_metric.cc +++ b/src/core/ext/filters/client_channel/backend_metric.cc @@ -26,12 +26,12 @@ namespace grpc_core { namespace { template -Map ParseMap( +std::map ParseMap( udpa_data_orca_v1_OrcaLoadReport* msg, EntryType** (*entry_func)(udpa_data_orca_v1_OrcaLoadReport*, size_t*), upb_strview (*key_func)(const EntryType*), double (*value_func)(const EntryType*), Arena* arena) { - Map result; + std::map result; size_t size; const auto* const* entries = entry_func(msg, &size); for (size_t i = 0; i < size; ++i) { diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index ed61537cb03..211f7ba39a5 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -291,7 +291,7 @@ class ChannelData { RefCountedPtr saved_service_config_; bool received_first_resolver_result_ = false; // The number of SubchannelWrapper instances referencing a given Subchannel. - Map subchannel_refcount_map_; + std::map subchannel_refcount_map_; // The set of SubchannelWrappers that currently exist. // No need to hold a ref, since the map is updated in the control-plane // combiner when the SubchannelWrappers are created and destroyed. @@ -299,8 +299,8 @@ class ChannelData { // Pending ConnectedSubchannel updates for each SubchannelWrapper. // Updates are queued here in the control plane combiner and then applied // in the data plane mutex when the picker is updated. - Map, RefCountedPtr, - RefCountedPtrLess> + std::map, RefCountedPtr, + RefCountedPtrLess> pending_subchannel_updates_; // @@ -321,7 +321,7 @@ class ChannelData { // synchronously via grpc_channel_num_external_connectivity_watchers(). // mutable Mutex external_watchers_mu_; - Map external_watchers_; + std::map external_watchers_; }; // @@ -1116,7 +1116,7 @@ class ChannelData::SubchannelWrapper : public SubchannelInterface { // subchannel. This is needed so that when the LB policy calls // CancelConnectivityStateWatch() with its watcher, we know the // corresponding WrapperWatcher to cancel on the underlying subchannel. - Map watcher_map_; + std::map watcher_map_; // To be accessed only in the control plane combiner. RefCountedPtr connected_subchannel_; // To be accessed only in the data plane mutex. diff --git a/src/core/ext/filters/client_channel/lb_policy.h b/src/core/ext/filters/client_channel/lb_policy.h index a037a5070c2..ad10316f8dd 100644 --- a/src/core/ext/filters/client_channel/lb_policy.h +++ b/src/core/ext/filters/client_channel/lb_policy.h @@ -21,6 +21,7 @@ #include +#include #include #include "src/core/ext/filters/client_channel/server_address.h" @@ -92,11 +93,11 @@ class LoadBalancingPolicy : public InternallyRefCounted { /// Application-specific requests cost metrics. Metric names are /// determined by the application. Each value is an absolute cost /// (e.g. 3487 bytes of storage) associated with the request. - Map request_cost; + std::map request_cost; /// Application-specific resource utilization metrics. Metric names /// are determined by the application. Each value is expressed as a /// fraction of total resources available. - Map utilization; + std::map utilization; }; /// Interface for accessing per-call state. diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index 49267128959..26238ff2b7c 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -479,8 +479,7 @@ int equal_cmp(void* /*p1*/, void* /*p2*/) { // token or client stats. A better approach might be to find somewhere // other than the subchannel args to store the LB token and client // stats. They could be stored in a map and then looked up for each - // call (although we'd need to make sure our Map<> implementation is - // performant enough). Or we could do something more complicated whereby + // call. Or we could do something more complicated whereby // we create our own subchannel wrapper to store them, although that would // involve a lot of refcounting overhead. // Given that we're trying to move from grpclb to xds at this point, diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc index f2378b36f02..fe77d6294c0 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc @@ -327,8 +327,8 @@ class XdsLb : public LoadBalancingPolicy { RefCountedPtr xds_policy_; - Map, OrphanablePtr, - XdsLocalityName::Less> + std::map, OrphanablePtr, + XdsLocalityName::Less> localities_; const uint32_t priority_; grpc_connectivity_state connectivity_state_ = GRPC_CHANNEL_IDLE; diff --git a/src/core/ext/filters/client_channel/subchannel.h b/src/core/ext/filters/client_channel/subchannel.h index d2b822b8397..be17de53373 100644 --- a/src/core/ext/filters/client_channel/subchannel.h +++ b/src/core/ext/filters/client_channel/subchannel.h @@ -293,8 +293,8 @@ class Subchannel { private: // TODO(roth): Once we can use C++-14 heterogeneous lookups, this can // be a set instead of a map. - Map> + std::map> watchers_; }; @@ -327,7 +327,7 @@ class Subchannel { private: class HealthWatcher; - Map, StringLess> map_; + std::map, StringLess> map_; }; class ConnectedSubchannelStateWatcher; diff --git a/src/core/ext/filters/client_channel/xds/xds_api.cc b/src/core/ext/filters/client_channel/xds/xds_api.cc index eeb6145c8f2..01874823b9c 100644 --- a/src/core/ext/filters/client_channel/xds/xds_api.cc +++ b/src/core/ext/filters/client_channel/xds/xds_api.cc @@ -114,9 +114,9 @@ void PopulateListValue(upb_arena* arena, google_protobuf_ListValue* list_value, } } -void PopulateMetadata( - upb_arena* arena, google_protobuf_Struct* metadata_pb, - const Map& metadata) { +void PopulateMetadata(upb_arena* arena, google_protobuf_Struct* metadata_pb, + const std::map& metadata) { for (const auto& p : metadata) { google_protobuf_Struct_FieldsEntry* field = google_protobuf_Struct_add_fields(metadata_pb, arena); diff --git a/src/core/ext/filters/client_channel/xds/xds_api.h b/src/core/ext/filters/client_channel/xds/xds_api.h index af176e23bca..70241334a9d 100644 --- a/src/core/ext/filters/client_channel/xds/xds_api.h +++ b/src/core/ext/filters/client_channel/xds/xds_api.h @@ -59,7 +59,7 @@ class XdsPriorityListUpdate { size_t size() const { return localities.size(); } - Map, Locality, XdsLocalityName::Less> + std::map, Locality, XdsLocalityName::Less> localities; }; diff --git a/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc b/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc index b71b4486a43..f2bba8faf96 100644 --- a/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +++ b/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc @@ -320,7 +320,7 @@ grpc_error* XdsBootstrap::ParseLocality(grpc_json* json) { InlinedVector XdsBootstrap::ParseMetadataStruct( grpc_json* json, - Map* result) { + std::map* result) { InlinedVector error_list; for (grpc_json* child = json->child; child != nullptr; child = child->next) { if (child->key == nullptr) { diff --git a/src/core/ext/filters/client_channel/xds/xds_bootstrap.h b/src/core/ext/filters/client_channel/xds/xds_bootstrap.h index 404cb6ab239..c0712ec24ed 100644 --- a/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +++ b/src/core/ext/filters/client_channel/xds/xds_bootstrap.h @@ -40,7 +40,7 @@ class XdsBootstrap { double double_value; const char* string_value; bool bool_value; - Map struct_value; + std::map struct_value; std::vector list_value; }; @@ -50,7 +50,7 @@ class XdsBootstrap { const char* locality_region = nullptr; const char* locality_zone = nullptr; const char* locality_subzone = nullptr; - Map metadata; + std::map metadata; }; struct ChannelCreds { @@ -80,7 +80,8 @@ class XdsBootstrap { grpc_error* ParseLocality(grpc_json* json); InlinedVector ParseMetadataStruct( - grpc_json* json, Map* result); + grpc_json* json, + std::map* result); InlinedVector ParseMetadataList( grpc_json* json, std::vector* result); grpc_error* ParseMetadataValue(grpc_json* json, size_t idx, diff --git a/src/core/ext/filters/client_channel/xds/xds_client.h b/src/core/ext/filters/client_channel/xds/xds_client.h index c5fc08cf0c2..e3377ef52bc 100644 --- a/src/core/ext/filters/client_channel/xds/xds_client.h +++ b/src/core/ext/filters/client_channel/xds/xds_client.h @@ -171,9 +171,9 @@ class XdsClient : public InternallyRefCounted { }; struct ClusterState { - Map> + std::map> cluster_watchers; - Map> + std::map> endpoint_watchers; Set client_stats; // The latest data seen from EDS. diff --git a/src/core/ext/filters/client_channel/xds/xds_client_stats.h b/src/core/ext/filters/client_channel/xds/xds_client_stats.h index 9bbd3e44e8f..07b457a0bf4 100644 --- a/src/core/ext/filters/client_channel/xds/xds_client_stats.h +++ b/src/core/ext/filters/client_channel/xds/xds_client_stats.h @@ -111,9 +111,9 @@ class XdsClientStats { double total_metric_value_{0}; }; - using LoadMetricMap = Map, LoadMetric, StringLess>; + using LoadMetricMap = std::map, LoadMetric, StringLess>; using LoadMetricSnapshotMap = - Map, LoadMetric::Snapshot, StringLess>; + std::map, LoadMetric::Snapshot, StringLess>; struct Snapshot { // TODO(juanlishen): Change this to const method when const_iterator is @@ -180,12 +180,12 @@ class XdsClientStats { // UniquePtr<>. We should remove this wrapper if the value type of Map<> // doesn't have to be movable. using LocalityStatsMap = - Map, RefCountedPtr, - XdsLocalityName::Less>; + std::map, RefCountedPtr, + XdsLocalityName::Less>; using LocalityStatsSnapshotMap = - Map, LocalityStats::Snapshot, - XdsLocalityName::Less>; - using DroppedRequestsMap = Map, uint64_t, StringLess>; + std::map, LocalityStats::Snapshot, + XdsLocalityName::Less>; + using DroppedRequestsMap = std::map, uint64_t, StringLess>; using DroppedRequestsSnapshotMap = DroppedRequestsMap; struct Snapshot { diff --git a/src/core/lib/channel/channelz.h b/src/core/lib/channel/channelz.h index 545b9ebeb88..5a063b4df96 100644 --- a/src/core/lib/channel/channelz.h +++ b/src/core/lib/channel/channelz.h @@ -221,8 +221,8 @@ class ChannelNode : public BaseNode { // TODO(roth): We don't actually use the values here, only the keys, so // these should be sets instead of maps, but we don't currently have a set // implementation. Change this if/when we have one. - Map child_channels_; - Map child_subchannels_; + std::map child_channels_; + std::map child_subchannels_; }; // Handles channelz bookkeeping for servers @@ -262,8 +262,8 @@ class ServerNode : public BaseNode { CallCountingHelper call_counter_; ChannelTrace trace_; Mutex child_mu_; // Guards child maps below. - Map> child_sockets_; - Map> child_listen_sockets_; + std::map> child_sockets_; + std::map> child_listen_sockets_; }; // Handles channelz bookkeeping for sockets diff --git a/src/core/lib/channel/channelz_registry.h b/src/core/lib/channel/channelz_registry.h index e04d7c44888..c60a5554fb9 100644 --- a/src/core/lib/channel/channelz_registry.h +++ b/src/core/lib/channel/channelz_registry.h @@ -87,7 +87,7 @@ class ChannelzRegistry { // protects members Mutex mu_; - Map node_map_; + std::map node_map_; intptr_t uuid_generator_ = 0; }; diff --git a/src/core/lib/gprpp/map.h b/src/core/lib/gprpp/map.h index fc44cd2cb8e..0ad92d0bfc8 100644 --- a/src/core/lib/gprpp/map.h +++ b/src/core/lib/gprpp/map.h @@ -23,21 +23,13 @@ #include -#include -#include -#include #include -#include "src/core/lib/gpr/useful.h" -#include "src/core/lib/gprpp/memory.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/string_view.h" namespace grpc_core { -template > -using Map = std::map>>; - struct StringLess { bool operator()(const char* a, const char* b) const { return strcmp(a, b) < 0; diff --git a/src/core/lib/security/credentials/credentials.cc b/src/core/lib/security/credentials/credentials.cc index f2ec9b7f2f2..37678715704 100644 --- a/src/core/lib/security/credentials/credentials.cc +++ b/src/core/lib/security/credentials/credentials.cc @@ -45,18 +45,18 @@ void grpc_channel_credentials_release(grpc_channel_credentials* creds) { if (creds) creds->Unref(); } -static grpc_core::Map, - grpc_core::RefCountedPtr, - grpc_core::StringLess>* g_grpc_control_plane_creds; +static std::map, + grpc_core::RefCountedPtr, + grpc_core::StringLess>* g_grpc_control_plane_creds; static gpr_mu g_control_plane_creds_mu; static void do_control_plane_creds_init() { gpr_mu_init(&g_control_plane_creds_mu); GPR_ASSERT(g_grpc_control_plane_creds == nullptr); g_grpc_control_plane_creds = grpc_core::New< - grpc_core::Map, - grpc_core::RefCountedPtr, - grpc_core::StringLess>>(); + std::map, + grpc_core::RefCountedPtr, + grpc_core::StringLess>>(); } void grpc_control_plane_credentials_init() { diff --git a/src/core/lib/security/credentials/credentials.h b/src/core/lib/security/credentials/credentials.h index 16f0454907b..e0700c41a92 100644 --- a/src/core/lib/security/credentials/credentials.h +++ b/src/core/lib/security/credentials/credentials.h @@ -148,9 +148,9 @@ struct grpc_channel_credentials private: const char* type_; - grpc_core::Map, - grpc_core::RefCountedPtr, - grpc_core::StringLess> + std::map, + grpc_core::RefCountedPtr, + grpc_core::StringLess> local_control_plane_creds_; }; diff --git a/src/core/lib/transport/connectivity_state.h b/src/core/lib/transport/connectivity_state.h index 06817340739..b2add5d7df5 100644 --- a/src/core/lib/transport/connectivity_state.h +++ b/src/core/lib/transport/connectivity_state.h @@ -119,8 +119,8 @@ class ConnectivityStateTracker { Atomic state_; // TODO(roth): Once we can use C++-14 heterogeneous lookups, this can // be a set instead of a map. - Map> + std::map> watchers_; };