Skip to content

Commit 60bea3d

Browse files
[ADT] "Inline" TestAndEraseFromSet into SetVector::remove_if (NFC) (#155790)
TestAndEraseFromSet is used only from SetVector::remove_if. This patch "inlines" the struct into its sole user in the form of a lambda function. FWIW, "git blame" shows that TestAndEraseFromSet dates back to 2012. Most likely, the lambda function wasn't an option yet back then.
1 parent 026918d commit 60bea3d

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

llvm/include/llvm/ADT/SetVector.h

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,13 @@ class SetVector {
250250
if (isSmall())
251251
return llvm::remove_if(vector_, P);
252252

253-
return llvm::remove_if(vector_,
254-
TestAndEraseFromSet<UnaryPredicate>(P, set_));
253+
return llvm::remove_if(vector_, [&](const value_type &V) {
254+
if (P(V)) {
255+
set_.erase(V);
256+
return true;
257+
}
258+
return false;
259+
});
255260
}();
256261

257262
if (I == vector_.end())
@@ -331,29 +336,6 @@ class SetVector {
331336
}
332337

333338
private:
334-
/// A wrapper predicate designed for use with std::remove_if.
335-
///
336-
/// This predicate wraps a predicate suitable for use with std::remove_if to
337-
/// call set_.erase(x) on each element which is slated for removal.
338-
template <typename UnaryPredicate>
339-
class TestAndEraseFromSet {
340-
UnaryPredicate P;
341-
set_type &set_;
342-
343-
public:
344-
TestAndEraseFromSet(UnaryPredicate P, set_type &set_)
345-
: P(std::move(P)), set_(set_) {}
346-
347-
template <typename ArgumentT>
348-
bool operator()(const ArgumentT &Arg) {
349-
if (P(Arg)) {
350-
set_.erase(Arg);
351-
return true;
352-
}
353-
return false;
354-
}
355-
};
356-
357339
[[nodiscard]] static constexpr bool canBeSmall() { return N != 0; }
358340

359341
[[nodiscard]] bool isSmall() const { return set_.empty(); }

0 commit comments

Comments
 (0)