Skip to content

Commit b84a97c

Browse files
[ADT] Use SmallPtrSet or SmallSet flexibly (NFC)
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 e0acf65 commit b84a97c

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

llvm/unittests/ADT/DenseMapTest.cpp

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

390+
template <typename T, unsigned N>
391+
using UniversalSmallSet =
392+
std::conditional_t<std::is_pointer_v<T>, SmallPtrSet<T, N>, SmallSet<T, N>>;
393+
390394
TYPED_TEST(DenseMapTest, KeysValuesIterator) {
391-
SmallSet<typename TypeParam::key_type, 10> Keys;
392-
SmallSet<typename TypeParam::mapped_type, 10> Values;
395+
UniversalSmallSet<typename TypeParam::key_type, 10> Keys;
396+
UniversalSmallSet<typename TypeParam::mapped_type, 10> Values;
393397
for (int I = 0; I < 10; ++I) {
394398
auto K = this->getKey(I);
395399
auto V = this->getValue(I);
@@ -398,8 +402,8 @@ TYPED_TEST(DenseMapTest, KeysValuesIterator) {
398402
this->Map[K] = V;
399403
}
400404

401-
SmallSet<typename TypeParam::key_type, 10> ActualKeys;
402-
SmallSet<typename TypeParam::mapped_type, 10> ActualValues;
405+
UniversalSmallSet<typename TypeParam::key_type, 10> ActualKeys;
406+
UniversalSmallSet<typename TypeParam::mapped_type, 10> ActualValues;
403407
for (auto K : this->Map.keys())
404408
ActualKeys.insert(K);
405409
for (auto V : this->Map.values())
@@ -410,8 +414,8 @@ TYPED_TEST(DenseMapTest, KeysValuesIterator) {
410414
}
411415

412416
TYPED_TEST(DenseMapTest, ConstKeysValuesIterator) {
413-
SmallSet<typename TypeParam::key_type, 10> Keys;
414-
SmallSet<typename TypeParam::mapped_type, 10> Values;
417+
UniversalSmallSet<typename TypeParam::key_type, 10> Keys;
418+
UniversalSmallSet<typename TypeParam::mapped_type, 10> Values;
415419
for (int I = 0; I < 10; ++I) {
416420
auto K = this->getKey(I);
417421
auto V = this->getValue(I);
@@ -421,8 +425,8 @@ TYPED_TEST(DenseMapTest, ConstKeysValuesIterator) {
421425
}
422426

423427
const TypeParam &ConstMap = this->Map;
424-
SmallSet<typename TypeParam::key_type, 10> ActualKeys;
425-
SmallSet<typename TypeParam::mapped_type, 10> ActualValues;
428+
UniversalSmallSet<typename TypeParam::key_type, 10> ActualKeys;
429+
UniversalSmallSet<typename TypeParam::mapped_type, 10> ActualValues;
426430
for (auto K : ConstMap.keys())
427431
ActualKeys.insert(K);
428432
for (auto V : ConstMap.values())

0 commit comments

Comments
 (0)