From 4876e6911e439b68c82040a3774a37de0d3e78c0 Mon Sep 17 00:00:00 2001 From: Kevin Baichoo Date: Wed, 21 Jun 2023 20:39:27 -0400 Subject: [PATCH] Clean up: Use contains where count is being used as contains. (#28076) Signed-off-by: Kevin Baichoo --- source/common/common/utility.cc | 2 +- source/common/common/utility.h | 2 +- source/common/stream_info/filter_state_impl.cc | 2 +- source/common/upstream/cds_api_impl.cc | 2 +- source/common/upstream/cluster_manager_impl.cc | 2 +- source/extensions/clusters/eds/eds.cc | 2 +- source/extensions/config_subscription/grpc/grpc_mux_impl.cc | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/common/common/utility.cc b/source/common/common/utility.cc index c1dc9ed47b45..824558e391e3 100644 --- a/source/common/common/utility.cc +++ b/source/common/common/utility.cc @@ -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); } diff --git a/source/common/common/utility.h b/source/common/common/utility.h index a07a635ddf01..a616c3aebeff 100644 --- a/source/common/common/utility.h +++ b/source/common/common/utility.h @@ -828,7 +828,7 @@ class SetUtil { absl::flat_hash_set& 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); }); } }; diff --git a/source/common/stream_info/filter_state_impl.cc b/source/common/stream_info/filter_state_impl.cc index 9a997de0ccee..e59e1138cdaa 100644 --- a/source/common/stream_info/filter_state_impl.cc +++ b/source/common/stream_info/filter_state_impl.cc @@ -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) { diff --git a/source/common/upstream/cds_api_impl.cc b/source/common/upstream/cds_api_impl.cc index 64c2c5a25cce..ecb1d082a4b7 100644 --- a/source/common/upstream/cds_api_impl.cc +++ b/source/common/upstream/cds_api_impl.cc @@ -49,7 +49,7 @@ void CdsApiImpl::onConfigUpdate(const std::vector& 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; } } diff --git a/source/common/upstream/cluster_manager_impl.cc b/source/common/upstream/cluster_manager_impl.cc index 5229d60b68ee..12dbd970cd20 100644 --- a/source/common/upstream/cluster_manager_impl.cc +++ b/source/common/upstream/cluster_manager_impl.cc @@ -1126,7 +1126,7 @@ void ClusterManagerImpl::postThreadLocalClusterUpdate(ClusterManagerCluster& cm_ OptRef 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()); diff --git a/source/extensions/clusters/eds/eds.cc b/source/extensions/clusters/eds/eds.cc index 3341992dc8af..4aaea4dfba38 100644 --- a/source/extensions/clusters/eds/eds.cc +++ b/source/extensions/clusters/eds/eds.cc @@ -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; } diff --git a/source/extensions/config_subscription/grpc/grpc_mux_impl.cc b/source/extensions/config_subscription/grpc/grpc_mux_impl.cc index c5ba997b6f5b..924596483a2c 100644 --- a/source/extensions/config_subscription/grpc/grpc_mux_impl.cc +++ b/source/extensions/config_subscription/grpc/grpc_mux_impl.cc @@ -107,7 +107,7 @@ void GrpcMuxImpl::sendDiscoveryRequest(absl::string_view type_url) { absl::node_hash_set 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); }