Skip to content

Commit 4e98641

Browse files
[ADT] Use SmallPtrSet or SmallSet flexibly (NFC) (#154680)
I'm trying to remove the redirection in SmallSet.h: template <typename PointeeType, unsigned N> class SmallSet<PointeeType*, N> : public SmallPtrSet<PointeeType*, N> {}; to make it clear that we are using SmallPtrSet. There are only handful places that rely on this redirection. Now, this unit test is unique in that supply multiple key types via TYPED_TESTS. This patch adds UniversalSmallSet to work around the problem.
1 parent ec07d8e commit 4e98641

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

llvm/unittests/ADT/DenseMapTest.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,16 @@ TYPED_TEST(DenseMapTest, ConstIteratorTest) {
387387
EXPECT_TRUE(cit == cit2);
388388
}
389389

390+
// TYPED_TEST below cycles through different types. We define UniversalSmallSet
391+
// here so that we'll use SmallSet or SmallPtrSet depending on whether the
392+
// element type is a pointer.
393+
template <typename T, unsigned N>
394+
using UniversalSmallSet =
395+
std::conditional_t<std::is_pointer_v<T>, SmallPtrSet<T, N>, SmallSet<T, N>>;
396+
390397
TYPED_TEST(DenseMapTest, KeysValuesIterator) {
391-
SmallSet<typename TypeParam::key_type, 10> Keys;
392-
SmallSet<typename TypeParam::mapped_type, 10> Values;
398+
UniversalSmallSet<typename TypeParam::key_type, 10> Keys;
399+
UniversalSmallSet<typename TypeParam::mapped_type, 10> Values;
393400
for (int I = 0; I < 10; ++I) {
394401
auto K = this->getKey(I);
395402
auto V = this->getValue(I);
@@ -398,8 +405,8 @@ TYPED_TEST(DenseMapTest, KeysValuesIterator) {
398405
this->Map[K] = V;
399406
}
400407

401-
SmallSet<typename TypeParam::key_type, 10> ActualKeys;
402-
SmallSet<typename TypeParam::mapped_type, 10> ActualValues;
408+
UniversalSmallSet<typename TypeParam::key_type, 10> ActualKeys;
409+
UniversalSmallSet<typename TypeParam::mapped_type, 10> ActualValues;
403410
for (auto K : this->Map.keys())
404411
ActualKeys.insert(K);
405412
for (auto V : this->Map.values())
@@ -410,8 +417,8 @@ TYPED_TEST(DenseMapTest, KeysValuesIterator) {
410417
}
411418

412419
TYPED_TEST(DenseMapTest, ConstKeysValuesIterator) {
413-
SmallSet<typename TypeParam::key_type, 10> Keys;
414-
SmallSet<typename TypeParam::mapped_type, 10> Values;
420+
UniversalSmallSet<typename TypeParam::key_type, 10> Keys;
421+
UniversalSmallSet<typename TypeParam::mapped_type, 10> Values;
415422
for (int I = 0; I < 10; ++I) {
416423
auto K = this->getKey(I);
417424
auto V = this->getValue(I);
@@ -421,8 +428,8 @@ TYPED_TEST(DenseMapTest, ConstKeysValuesIterator) {
421428
}
422429

423430
const TypeParam &ConstMap = this->Map;
424-
SmallSet<typename TypeParam::key_type, 10> ActualKeys;
425-
SmallSet<typename TypeParam::mapped_type, 10> ActualValues;
431+
UniversalSmallSet<typename TypeParam::key_type, 10> ActualKeys;
432+
UniversalSmallSet<typename TypeParam::mapped_type, 10> ActualValues;
426433
for (auto K : ConstMap.keys())
427434
ActualKeys.insert(K);
428435
for (auto V : ConstMap.values())

0 commit comments

Comments
 (0)