@@ -59,24 +59,20 @@ template <typename ValueT> struct SparseSetValTraits {
5959 }
6060};
6161
62- // / SparseSetValFunctor - Helper class for selecting SparseSetValTraits. The
63- // / generic implementation handles ValueT classes which either provide
64- // / getSparseSetIndex() or specialize SparseSetValTraits<>.
62+ // / SparseSetValFunctor - Helper class for getting a value's index.
6563// /
64+ // / In the generic case, this is done via SparseSetValTraits. When the value
65+ // / type is the same as the key type, the KeyFunctor is used directly.
6666template <typename KeyT, typename ValueT, typename KeyFunctorT>
6767struct SparseSetValFunctor {
6868 unsigned operator ()(const ValueT &Val) const {
69- return SparseSetValTraits<ValueT>::getValIndex (Val);
69+ if constexpr (std::is_same_v<KeyT, ValueT>)
70+ return KeyFunctorT ()(Val);
71+ else
72+ return SparseSetValTraits<ValueT>::getValIndex (Val);
7073 }
7174};
7275
73- // / SparseSetValFunctor<KeyT, KeyT> - Helper class for the common case of
74- // / identity key/value sets.
75- template <typename KeyT, typename KeyFunctorT>
76- struct SparseSetValFunctor <KeyT, KeyT, KeyFunctorT> {
77- unsigned operator ()(const KeyT &Key) const { return KeyFunctorT ()(Key); }
78- };
79-
8076// / SparseSet - Fast set implementation for objects that can be identified by
8177// / small unsigned keys.
8278// /
0 commit comments