cleanup: replace erase-remove idiom with std::erase_if or absl::erase_if - #46663
Merged
Conversation
Amila-Rukshan
requested review from
RyanTheOptimist,
agrawroh,
botengyao,
mattklein123,
ravenblackx and
yanavlasov
as code owners
August 12, 2026 09:23
Amila-Rukshan
force-pushed
the
improve-readability
branch
from
August 12, 2026 09:33
e5cf083 to
06a37f8
Compare
…ve idiom Signed-off-by: Amila Senadheera <amilaruk1995@gmail.com>
Amila-Rukshan
force-pushed
the
improve-readability
branch
from
August 12, 2026 10:26
06a37f8 to
c82105c
Compare
Contributor
Author
|
/retest |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR modernizes element-removal code paths across Envoy by replacing the erase-remove idiom with std::erase_if (for standard containers) and absl::erase_if (for Abseil containers), improving readability while aiming to preserve behavior.
Changes:
- Replaced
container.erase(std::remove_if(...), end())withstd::erase_if(container, pred)for standard containers. - Replaced the equivalent pattern with
absl::erase_if(container, pred)for Abseil containers.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/server/config_validation/xds_verifier.cc | Uses std::erase_if to remove listener entries marked REMOVED in both SOTW and delta update paths. |
| test/server/config_validation/xds_fuzz.cc | Uses std::erase_if to remove listeners by name in fuzz test helper. |
| source/extensions/filters/http/cache_v2/cache_sessions_impl.cc | Uses std::erase_if to remove out-of-range body subscribers while performing existing side effects. |
| source/extensions/clusters/dynamic_forward_proxy/cluster.cc | Uses std::erase_if to remove draining connection entries from the per-key connection info vector. |
| source/extensions/bootstrap/reverse_tunnel/downstream_socket_interface/reverse_connection_io_handle.cc | Uses std::erase_if to remove stale connection wrappers from the wrappers vector. |
| source/common/upstream/upstream_impl.cc | Uses std::erase_if to prune host vectors in dynamic host list update logic. |
| source/common/upstream/cluster_manager_impl.cc | Uses std::erase_if to remove hosts from hosts_added_ that are also in hosts_removed_. |
| source/common/http/http_server_properties_cache_impl.cc | Uses std::erase_if to drop expired alternate protocols while preserving existing update behavior. |
| source/common/http/header_map_impl.h | Switches removal on absl::InlinedVector to absl::erase_if (with a now-outdated explanatory comment). |
| source/common/event/evwatch_observer_manager_impl.cc | Uses std::erase_if to purge nulled observer entries from the observer list. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
botengyao
reviewed
Aug 14, 2026
botengyao
left a comment
Member
There was a problem hiding this comment.
thanks for the improvement, lgtm module the nit.
/wait
Signed-off-by: Amila Senadheera <amilaruk1995@gmail.com>
Contributor
Author
|
@botengyao, @wbpcode, I have addressed the nit. |
wbpcode
approved these changes
Aug 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Replace the traditional erase-remove idiom with the more concise
std::erase_ifandabsl::erase_ifAPIs where applicable.This improves readability by expressing the intent to remove elements matching a predicate directly, while preserving the existing behavior.
Changes
Replace
std::remove_iffollowed byerasewithstd::erase_iffor standard containers.Replace the same pattern with
absl::erase_iffor supported Abseil containers.No functional behavior changes are intended.