Skip to content

Commit

Permalink
Clean up: Use contains where count is being used as contains. (#28076)
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Baichoo <kbaichoo@google.com>
  • Loading branch information
KBaichoo authored Jun 22, 2023
1 parent 84d0b10 commit 4876e69
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion source/common/common/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ std::string StringUtil::removeTokens(absl::string_view source, absl::string_view
absl::string_view joiner) {
auto values = Envoy::StringUtil::splitToken(source, delimiters, false, true);
auto end = std::remove_if(values.begin(), values.end(),
[&](absl::string_view t) { return tokens_to_remove.count(t) != 0; });
[&](absl::string_view t) { return tokens_to_remove.contains(t); });
return absl::StrJoin(values.begin(), end, joiner);
}

Expand Down
2 changes: 1 addition & 1 deletion source/common/common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ class SetUtil {
absl::flat_hash_set<T>& result_set) {
std::copy_if(original_set.begin(), original_set.end(),
std::inserter(result_set, result_set.begin()),
[&remove_set](const T& v) -> bool { return remove_set.count(v) == 0; });
[&remove_set](const T& v) -> bool { return !remove_set.contains(v); });
}
};

Expand Down
2 changes: 1 addition & 1 deletion source/common/stream_info/filter_state_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ FilterState::ObjectsPtr FilterStateImpl::objectsSharedWithUpstreamConnection() c
}

bool FilterStateImpl::hasDataWithNameInternally(absl::string_view data_name) const {
return data_storage_.count(data_name) > 0;
return data_storage_.contains(data_name);
}

void FilterStateImpl::maybeCreateParent(ParentAccessMode parent_access_mode) {
Expand Down
2 changes: 1 addition & 1 deletion source/common/upstream/cds_api_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void CdsApiImpl::onConfigUpdate(const std::vector<Config::DecodedResourceRef>& r
for (const auto& [cluster_name, _] : all_existing_clusters.warming_clusters_) {
UNREFERENCED_PARAMETER(_);
// Do not add the cluster twice when the cluster is both active and warming.
if (all_existing_clusters.active_clusters_.count(cluster_name) == 0) {
if (!all_existing_clusters.active_clusters_.contains(cluster_name)) {
*to_remove_repeated.Add() = cluster_name;
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/common/upstream/cluster_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ void ClusterManagerImpl::postThreadLocalClusterUpdate(ClusterManagerCluster& cm_
OptRef<ThreadLocalClusterManagerImpl> cluster_manager) {
ThreadLocalClusterManagerImpl::ClusterEntry* new_cluster = nullptr;
if (add_or_update_cluster) {
if (cluster_manager->thread_local_clusters_.count(info->name()) > 0) {
if (cluster_manager->thread_local_clusters_.contains(info->name())) {
ENVOY_LOG(debug, "updating TLS cluster {}", info->name());
} else {
ENVOY_LOG(debug, "adding TLS cluster {}", info->name());
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/clusters/eds/eds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void EdsClusterImpl::BatchUpdateHelper::updateLocalityEndpoints(

// When the configuration contains duplicate hosts, only the first one will be retained.
const auto address_as_string = address->asString();
if (all_new_hosts.count(address_as_string) > 0) {
if (all_new_hosts.contains(address_as_string)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void GrpcMuxImpl::sendDiscoveryRequest(absl::string_view type_url) {
absl::node_hash_set<std::string> resources;
for (const auto* watch : api_state.watches_) {
for (const std::string& resource : watch->resources_) {
if (resources.count(resource) == 0) {
if (!resources.contains(resource)) {
resources.emplace(resource);
request.add_resource_names(resource);
}
Expand Down

0 comments on commit 4876e69

Please sign in to comment.