diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2013-11-20 11:14:33 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2013-11-20 11:14:33 +0000 |
commit | 55758e9691410b9b3bee24f37e0255e93628e46c (patch) | |
tree | d25d206e78276ad6a36e42533a0ca6aa527194d9 /llvm/unittests/ADT/SmallPtrSetTest.cpp | |
parent | 3dedf827f899f1c14dda1a5a0e909da1dd090f95 (diff) | |
download | bcm5719-llvm-55758e9691410b9b3bee24f37e0255e93628e46c.tar.gz bcm5719-llvm-55758e9691410b9b3bee24f37e0255e93628e46c.zip |
Give SmallPtrSet move semantics when we have R-value references.
Somehow, this ADT got missed which is moderately terrifying considering
the efficiency of move for it.
The code to implement move semantics for it is pretty horrible
currently but was written to reasonably closely match the rest of the
code. Unittests that cover both copying and moving (at a basic level)
added.
llvm-svn: 195239
Diffstat (limited to 'llvm/unittests/ADT/SmallPtrSetTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/SmallPtrSetTest.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/SmallPtrSetTest.cpp b/llvm/unittests/ADT/SmallPtrSetTest.cpp index f85d7c941eb..1b564ac05ac 100644 --- a/llvm/unittests/ADT/SmallPtrSetTest.cpp +++ b/llvm/unittests/ADT/SmallPtrSetTest.cpp @@ -71,6 +71,55 @@ TEST(SmallPtrSetTest, GrowthTest) { EXPECT_EQ(1,buf[i]); } +TEST(SmallPtrSetTest, CopyAndMoveTest) { + int buf[8]; + for (int i = 0; i < 8; ++i) + buf[i] = 0; + + SmallPtrSet<int *, 4> s1; + s1.insert(&buf[0]); + s1.insert(&buf[1]); + s1.insert(&buf[2]); + s1.insert(&buf[3]); + EXPECT_EQ(4U, s1.size()); + for (int i = 0; i < 8; ++i) + if (i < 4) + EXPECT_TRUE(s1.count(&buf[i])); + else + EXPECT_FALSE(s1.count(&buf[i])); + + SmallPtrSet<int *, 4> s2(s1); + EXPECT_EQ(4U, s2.size()); + for (int i = 0; i < 8; ++i) + if (i < 4) + EXPECT_TRUE(s2.count(&buf[i])); + else + EXPECT_FALSE(s2.count(&buf[i])); + + s1 = s2; + EXPECT_EQ(4U, s1.size()); + for (int i = 0; i < 8; ++i) + if (i < 4) + EXPECT_TRUE(s1.count(&buf[i])); + else + EXPECT_FALSE(s1.count(&buf[i])); + + SmallPtrSet<int *, 4> s3(llvm_move(s1)); + EXPECT_EQ(4U, s3.size()); + for (int i = 0; i < 8; ++i) + if (i < 4) + EXPECT_TRUE(s3.count(&buf[i])); + else + EXPECT_FALSE(s3.count(&buf[i])); + + s1 = llvm_move(s3); + EXPECT_EQ(4U, s1.size()); + for (int i = 0; i < 8; ++i) + if (i < 4) + EXPECT_TRUE(s1.count(&buf[i])); + else + EXPECT_FALSE(s1.count(&buf[i])); +} TEST(SmallPtrSetTest, SwapTest) { int buf[10]; |