[NFC] Define NumBuiltinElts utility just once at the beginning of SmallVectorTest file
Extracted from: https://reviews.llvm.org/D130268
Differential Revision: https://reviews.llvm.org/D131173
GitOrigin-RevId: 7d7a712c9861592e64a9dc09038e24c6b062ba59
diff --git a/unittests/ADT/SmallVectorTest.cpp b/unittests/ADT/SmallVectorTest.cpp
index d59ece2..1ba3e7e 100644
--- a/unittests/ADT/SmallVectorTest.cpp
+++ b/unittests/ADT/SmallVectorTest.cpp
@@ -202,6 +202,11 @@
}
}
+template <typename T, unsigned N>
+static unsigned NumBuiltinElts(const SmallVector<T, N> &) {
+ return N;
+}
+
class SmallVectorTestBase : public testing::Test {
protected:
void SetUp() override { Constructable::reset(); }
@@ -862,9 +867,6 @@
protected:
VectorT1 theVector;
VectorT2 otherVector;
-
- template <typename T, unsigned N>
- static unsigned NumBuiltinElts(const SmallVector<T, N>&) { return N; }
};
typedef ::testing::Types<
@@ -904,7 +906,7 @@
// If the source vector (otherVector) was in small-mode, assert that we just
// moved the data pointer over.
- EXPECT_TRUE(this->NumBuiltinElts(U) == 4 || V.data() == OrigDataPtr);
+ EXPECT_TRUE(NumBuiltinElts(U) == 4 || V.data() == OrigDataPtr);
// There shouldn't be any live objects any more.
V.clear();
@@ -1137,11 +1139,6 @@
VectorT V;
- template <typename T, unsigned N>
- static unsigned NumBuiltinElts(const SmallVector<T, N> &) {
- return N;
- }
-
template <class T> static bool isValueType() {
return std::is_same<T, typename VectorT::value_type>::value;
}
@@ -1167,7 +1164,7 @@
TYPED_TEST(SmallVectorReferenceInvalidationTest, PushBack) {
// Note: setup adds [1, 2, ...] to V until it's at capacity in small mode.
auto &V = this->V;
- int N = this->NumBuiltinElts(V);
+ int N = NumBuiltinElts(V);
// Push back a reference to last element when growing from small storage.
V.push_back(V.back());
@@ -1189,7 +1186,7 @@
TYPED_TEST(SmallVectorReferenceInvalidationTest, PushBackMoved) {
// Note: setup adds [1, 2, ...] to V until it's at capacity in small mode.
auto &V = this->V;
- int N = this->NumBuiltinElts(V);
+ int N = NumBuiltinElts(V);
// Push back a reference to last element when growing from small storage.
V.push_back(std::move(V.back()));
@@ -1218,7 +1215,7 @@
TYPED_TEST(SmallVectorReferenceInvalidationTest, Resize) {
auto &V = this->V;
(void)V;
- int N = this->NumBuiltinElts(V);
+ int N = NumBuiltinElts(V);
V.resize(N + 1, V.back());
EXPECT_EQ(N, V.back());
@@ -1233,7 +1230,7 @@
auto &V = this->V;
(void)V;
V.append(1, V.back());
- int N = this->NumBuiltinElts(V);
+ int N = NumBuiltinElts(V);
EXPECT_EQ(N, V[N - 1]);
// Append enough more elements that V will grow again. This tests growing
@@ -1251,7 +1248,7 @@
#if !defined(NDEBUG) && GTEST_HAS_DEATH_TEST
EXPECT_DEATH(V.append(V.begin(), V.begin() + 1), this->AssertionMessage);
- ASSERT_EQ(3u, this->NumBuiltinElts(V));
+ ASSERT_EQ(3u, NumBuiltinElts(V));
ASSERT_EQ(3u, V.size());
V.pop_back();
ASSERT_EQ(2u, V.size());
@@ -1266,7 +1263,7 @@
// Note: setup adds [1, 2, ...] to V until it's at capacity in small mode.
auto &V = this->V;
(void)V;
- int N = this->NumBuiltinElts(V);
+ int N = NumBuiltinElts(V);
ASSERT_EQ(unsigned(N), V.size());
ASSERT_EQ(unsigned(N), V.capacity());
@@ -1366,7 +1363,7 @@
// Cover NumToInsert <= this->end() - I.
V.insert(V.begin() + 1, 1, V.back());
- int N = this->NumBuiltinElts(V);
+ int N = NumBuiltinElts(V);
EXPECT_EQ(N, V[1]);
// Cover NumToInsert > this->end() - I, inserting enough elements that V will
@@ -1386,7 +1383,7 @@
EXPECT_DEATH(V.insert(V.begin(), V.begin(), V.begin() + 1),
this->AssertionMessage);
- ASSERT_EQ(3u, this->NumBuiltinElts(V));
+ ASSERT_EQ(3u, NumBuiltinElts(V));
ASSERT_EQ(3u, V.size());
V.pop_back();
ASSERT_EQ(2u, V.size());
@@ -1400,7 +1397,7 @@
TYPED_TEST(SmallVectorReferenceInvalidationTest, EmplaceBack) {
// Note: setup adds [1, 2, ...] to V until it's at capacity in small mode.
auto &V = this->V;
- int N = this->NumBuiltinElts(V);
+ int N = NumBuiltinElts(V);
// Push back a reference to last element when growing from small storage.
V.emplace_back(V.back());
@@ -1454,7 +1451,7 @@
TYPED_TEST(SmallVectorInternalReferenceInvalidationTest, EmplaceBack) {
// Note: setup adds [1, 2, ...] to V until it's at capacity in small mode.
auto &V = this->V;
- int N = this->NumBuiltinElts(V);
+ int N = NumBuiltinElts(V);
// Push back a reference to last element when growing from small storage.
V.emplace_back(V.back().first, V.back().second);