[ADT] Specialize std::swap() for SetVector

This is intended to address a compile-time regression from
1eddce4177. A SmallPtrSet was
replaced with a SetVector there, which had an unexpected large
compile-time impact. It turns out that this structure is getting
swapped a lot, and previously this used an optimized std::swap()
specialization for SmallPtrSet. Now it ends up using the default,
triple-move based implementation, which is much more expensive.

This patch (partly) addresses the issue by specializing std::swap()
for SetVector.

Differential Revision: https://reviews.llvm.org/D82230
This commit is contained in:
Nikita Popov 2020-06-19 20:25:33 +02:00
parent 77c9aafc5d
commit b9c2dd11a5
1 changed files with 23 additions and 0 deletions

View File

@ -263,6 +263,11 @@ public:
remove(*SI);
}
void swap(SetVector<T, Vector, Set> &RHS) {
set_.swap(RHS.set_);
vector_.swap(RHS.vector_);
}
private:
/// A wrapper predicate designed for use with std::remove_if.
///
@ -308,4 +313,22 @@ public:
} // end namespace llvm
namespace std {
/// Implement std::swap in terms of SetVector swap.
template<typename T, typename V, typename S>
inline void
swap(llvm::SetVector<T, V, S> &LHS, llvm::SetVector<T, V, S> &RHS) {
LHS.swap(RHS);
}
/// Implement std::swap in terms of SmallSetVector swap.
template<typename T, unsigned N>
inline void
swap(llvm::SmallSetVector<T, N> &LHS, llvm::SmallSetVector<T, N> &RHS) {
LHS.swap(RHS);
}
} // end namespace std
#endif // LLVM_ADT_SETVECTOR_H