Use std::set<> where appropriate.

pull/20439/head
Mark D. Roth 5 years ago
parent 9fc4adae63
commit 0ed1202f84
  1. 13
      src/core/ext/filters/client_channel/client_channel.cc
  2. 4
      src/core/ext/filters/client_channel/subchannel.h
  3. 4
      src/core/lib/transport/connectivity_state.h

@ -26,6 +26,9 @@
#include <stdio.h>
#include <string.h>
#include <map>
#include <set>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
@ -286,9 +289,7 @@ class ChannelData {
// 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.
// TODO(roth): We really want to use a set here, not a map. Since we don't
// currently have a set implementation, we use a map and ignore the value.
std::map<SubchannelWrapper*, bool> subchannel_wrappers_;
std::set<SubchannelWrapper*> subchannel_wrappers_;
// 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.
@ -852,7 +853,7 @@ class ChannelData::SubchannelWrapper : public SubchannelInterface {
}
++it->second;
}
chand_->subchannel_wrappers_[this] = true;
chand_->subchannel_wrappers_.insert(this);
}
~SubchannelWrapper() {
@ -1668,8 +1669,8 @@ bool ChannelData::ProcessResolverResultLocked(
chand->health_check_service_name_.reset();
}
// Update health check service name used by existing subchannel wrappers.
for (const auto& p : chand->subchannel_wrappers_) {
p.first->UpdateHealthCheckServiceName(
for (auto* subchannel_wrapper : chand->subchannel_wrappers_) {
subchannel_wrapper->UpdateHealthCheckServiceName(
UniquePtr<char>(gpr_strdup(chand->health_check_service_name_.get())));
}
// Save service config.

@ -292,8 +292,8 @@ class Subchannel {
bool empty() const { return watchers_.empty(); }
private:
// TODO(roth): This could be a set instead of a map if we had a set
// implementation.
// TODO(roth): Once we can use C++-14 heterogenous lookups, this can
// be a set instead of a map.
std::map<ConnectivityStateWatcherInterface*,
OrphanablePtr<ConnectivityStateWatcherInterface>>
watchers_;

@ -108,8 +108,8 @@ class ConnectivityStateTracker {
private:
const char* name_;
Atomic<grpc_connectivity_state> state_;
// TODO(roth): This could be a set instead of a map if we had a set
// implementation.
// TODO(roth): Once we can use C++-14 heterogenous lookups, this can
// be a set instead of a map.
std::map<ConnectivityStateWatcherInterface*,
OrphanablePtr<ConnectivityStateWatcherInterface>>
watchers_;

Loading…
Cancel
Save