diff --git a/llvm/include/llvm/ADT/SparseSet.h b/llvm/include/llvm/ADT/SparseSet.h index 4697de097e7eb..2ac23cc4cfa13 100644 --- a/llvm/include/llvm/ADT/SparseSet.h +++ b/llvm/include/llvm/ADT/SparseSet.h @@ -59,24 +59,20 @@ template struct SparseSetValTraits { } }; -/// SparseSetValFunctor - Helper class for selecting SparseSetValTraits. The -/// generic implementation handles ValueT classes which either provide -/// getSparseSetIndex() or specialize SparseSetValTraits<>. +/// SparseSetValFunctor - Helper class for getting a value's index. /// +/// In the generic case, this is done via SparseSetValTraits. When the value +/// type is the same as the key type, the KeyFunctor is used directly. template struct SparseSetValFunctor { unsigned operator()(const ValueT &Val) const { - return SparseSetValTraits::getValIndex(Val); + if constexpr (std::is_same_v) + return KeyFunctorT()(Val); + else + return SparseSetValTraits::getValIndex(Val); } }; -/// SparseSetValFunctor - Helper class for the common case of -/// identity key/value sets. -template -struct SparseSetValFunctor { - unsigned operator()(const KeyT &Key) const { return KeyFunctorT()(Key); } -}; - /// SparseSet - Fast set implementation for objects that can be identified by /// small unsigned keys. ///