[llvm] e8755e7 - [ADT] "Inline" TestAndEraseFromMap into PriorityWorklist.h (NFC) (#156596)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 3 07:48:25 PDT 2025
Author: Kazu Hirata
Date: 2025-09-03T07:48:20-07:00
New Revision: e8755e71c770bf65a26842ed68262336d2508dfc
URL: https://github.com/llvm/llvm-project/commit/e8755e71c770bf65a26842ed68262336d2508dfc
DIFF: https://github.com/llvm/llvm-project/commit/e8755e71c770bf65a26842ed68262336d2508dfc.diff
LOG: [ADT] "Inline" TestAndEraseFromMap into PriorityWorklist.h (NFC) (#156596)
TestAndEraseFromMap is used only from PriorityWorklist::erase_if.
This patch "inlines" the struct into its sole user in the form of a
lambda function, eliminating a lot of boilerplate code.
Added:
Modified:
llvm/include/llvm/ADT/PriorityWorklist.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/PriorityWorklist.h b/llvm/include/llvm/ADT/PriorityWorklist.h
index 2b6510f42d569..144993a761ac3 100644
--- a/llvm/include/llvm/ADT/PriorityWorklist.h
+++ b/llvm/include/llvm/ADT/PriorityWorklist.h
@@ -191,8 +191,17 @@ class PriorityWorklist {
/// \returns true if any element is removed.
template <typename UnaryPredicate>
bool erase_if(UnaryPredicate P) {
- typename VectorT::iterator E =
- remove_if(V, TestAndEraseFromMap<UnaryPredicate>(P, M));
+ typename VectorT::iterator E = remove_if(V, [&](const T &Arg) {
+ if (Arg == T())
+ // Skip null values in the PriorityWorklist.
+ return false;
+
+ if (P(Arg)) {
+ M.erase(Arg);
+ return true;
+ }
+ return false;
+ });
if (E == V.end())
return false;
for (auto I = V.begin(); I != E; ++I)
@@ -214,34 +223,6 @@ class PriorityWorklist {
}
private:
- /// A wrapper predicate designed for use with std::remove_if.
- ///
- /// This predicate wraps a predicate suitable for use with std::remove_if to
- /// call M.erase(x) on each element which is slated for removal. This just
- /// allows the predicate to be move only which we can't do with lambdas
- /// today.
- template <typename UnaryPredicateT>
- class TestAndEraseFromMap {
- UnaryPredicateT P;
- MapT &M;
-
- public:
- TestAndEraseFromMap(UnaryPredicateT P, MapT &M)
- : P(std::move(P)), M(M) {}
-
- bool operator()(const T &Arg) {
- if (Arg == T())
- // Skip null values in the PriorityWorklist.
- return false;
-
- if (P(Arg)) {
- M.erase(Arg);
- return true;
- }
- return false;
- }
- };
-
/// The map from value to index in the vector.
MapT M;
More information about the llvm-commits
mailing list