diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-03-06 20:40:02 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-03-06 20:40:02 +0000 |
commit | 2945a32ffd0bf079de1b23db12bc8a0de596a167 (patch) | |
tree | a54746b6880314aa1eca572f0449adb4f491399f /unittests | |
parent | 54427e52197ecd8c748736d7bbb431f2bf65c90e (diff) | |
download | external_llvm-2945a32ffd0bf079de1b23db12bc8a0de596a167.zip external_llvm-2945a32ffd0bf079de1b23db12bc8a0de596a167.tar.gz external_llvm-2945a32ffd0bf079de1b23db12bc8a0de596a167.tar.bz2 |
SmallPtrSet: Provide a more efficient implementation of swap than the default triple-copy std::swap.
This currently assumes that both sets have the same SmallSize to keep the implementation simple,
a limitation that can be lifted if someone cares.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152143 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ADT/SmallPtrSetTest.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/unittests/ADT/SmallPtrSetTest.cpp b/unittests/ADT/SmallPtrSetTest.cpp new file mode 100644 index 0000000..9114875 --- /dev/null +++ b/unittests/ADT/SmallPtrSetTest.cpp @@ -0,0 +1,72 @@ +//===- llvm/unittest/ADT/SmallPtrSetTest.cpp ------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// SmallPtrSet unit tests. +// +//===----------------------------------------------------------------------===// + +#include "gtest/gtest.h" +#include "llvm/ADT/SmallPtrSet.h" + +using namespace llvm; + +// SmallPtrSet swapping test. +TEST(SmallPtrSetTest, SwapTest) { + int buf[10]; + + SmallPtrSet<int *, 2> a; + SmallPtrSet<int *, 2> b; + + a.insert(&buf[0]); + a.insert(&buf[1]); + b.insert(&buf[2]); + + std::swap(a, b); + + EXPECT_EQ(1U, a.size()); + EXPECT_EQ(2U, b.size()); + EXPECT_TRUE(a.count(&buf[2])); + EXPECT_TRUE(b.count(&buf[0])); + EXPECT_TRUE(b.count(&buf[1])); + + b.insert(&buf[3]); + std::swap(a, b); + + EXPECT_EQ(3U, a.size()); + EXPECT_EQ(1U, b.size()); + EXPECT_TRUE(a.count(&buf[0])); + EXPECT_TRUE(a.count(&buf[1])); + EXPECT_TRUE(a.count(&buf[3])); + EXPECT_TRUE(b.count(&buf[2])); + + std::swap(a, b); + + EXPECT_EQ(1U, a.size()); + EXPECT_EQ(3U, b.size()); + EXPECT_TRUE(a.count(&buf[2])); + EXPECT_TRUE(b.count(&buf[0])); + EXPECT_TRUE(b.count(&buf[1])); + EXPECT_TRUE(b.count(&buf[3])); + + a.insert(&buf[4]); + a.insert(&buf[5]); + a.insert(&buf[6]); + + std::swap(b, a); + + EXPECT_EQ(3U, a.size()); + EXPECT_EQ(4U, b.size()); + EXPECT_TRUE(b.count(&buf[2])); + EXPECT_TRUE(b.count(&buf[4])); + EXPECT_TRUE(b.count(&buf[5])); + EXPECT_TRUE(b.count(&buf[6])); + EXPECT_TRUE(a.count(&buf[0])); + EXPECT_TRUE(a.count(&buf[1])); + EXPECT_TRUE(a.count(&buf[3])); +} |