[llvm] [ADT] Make set_subtract more efficient when subtrahend is larger (NFC) (PR #98702)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 15 11:48:56 PDT 2024
================
@@ -94,7 +94,24 @@ S1Ty set_difference(const S1Ty &S1, const S2Ty &S2) {
/// set_subtract(A, B) - Compute A := A - B
///
+/// Selects the set to iterate based on the relative sizes of A and B for better
+/// efficiency.
+///
template <class S1Ty, class S2Ty> void set_subtract(S1Ty &S1, const S2Ty &S2) {
+ using ElemTy = decltype(*S1.begin());
+ // A couple callers pass a vector for S2, which doesn't support count(), and
+ // wouldn't be efficient if it did. In the absence of a more direct check,
+ // ensure the type supports the contains or find interfaces.
+ if constexpr (detail::HasMemberContains<S2Ty, ElemTy> ||
+ detail::HasMemberFind<S2Ty, ElemTy>) {
----------------
nikic wrote:
I don't think there is a need to support find() here, especially as the rest of SetOperations.h does not support it either.
https://github.com/llvm/llvm-project/pull/98702
More information about the llvm-commits
mailing list