diff options
author | Mehdi Amini <mehdi.amini@apple.com> | 2016-03-25 23:25:06 +0000 |
---|---|---|
committer | Mehdi Amini <mehdi.amini@apple.com> | 2016-03-25 23:25:06 +0000 |
commit | 412989750ddebeb7022ae82df6b8fcb51c47d85a (patch) | |
tree | 761a05f32d72f14f6e0853487486578520c2e07f /llvm/unittests/ADT/StringMapTest.cpp | |
parent | 221cfdd7b141ebe5c89092ce2c37c928233dce54 (diff) | |
download | llvm-412989750ddebeb7022ae82df6b8fcb51c47d85a.zip llvm-412989750ddebeb7022ae82df6b8fcb51c47d85a.tar.gz llvm-412989750ddebeb7022ae82df6b8fcb51c47d85a.tar.bz2 |
StringMap/DenseMap unittests: use piecewise_construct and ensure no copy occurs.
This makes us no longer relying on move-construction elision by the compiler.
Suggested by D. Blaikie.
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 264475
Diffstat (limited to 'llvm/unittests/ADT/StringMapTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/StringMapTest.cpp | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/llvm/unittests/ADT/StringMapTest.cpp b/llvm/unittests/ADT/StringMapTest.cpp index 4deb48c..562126e 100644 --- a/llvm/unittests/ADT/StringMapTest.cpp +++ b/llvm/unittests/ADT/StringMapTest.cpp @@ -391,21 +391,16 @@ TEST(StringMapCustomTest, InitialSizeTest) { for (auto Size : {1, 32, 67}) { StringMap<CountCtorCopyAndMove> Map(Size); auto NumBuckets = Map.getNumBuckets(); - - // Prepare the elts in a vector. We do this as a pre-step to shield us - // against the internals of std::pair which can introduce spurious move/copy - std::vector<std::pair<std::string, CountCtorCopyAndMove>> Elts; - for (int i = 0; i < Size; ++i) - Elts.emplace_back(Twine(i).str(), CountCtorCopyAndMove()); - CountCtorCopyAndMove::Move = 0; CountCtorCopyAndMove::Copy = 0; for (int i = 0; i < Size; ++i) - Map.insert(Elts[i]); - // After the inital copy, the map will move the Elts in the Entry. - EXPECT_EQ((unsigned)Size, CountCtorCopyAndMove::Move); + Map.insert(std::pair<std::string, CountCtorCopyAndMove>( + std::piecewise_construct, std::forward_as_tuple(Twine(i).str()), + std::forward_as_tuple(i))); + // After the inital move, the map will move the Elts in the Entry. + EXPECT_EQ((unsigned)Size * 2, CountCtorCopyAndMove::Move); // We copy once the pair from the Elts vector - EXPECT_EQ((unsigned)Size, CountCtorCopyAndMove::Copy); + EXPECT_EQ(0u, CountCtorCopyAndMove::Copy); // Check that the map didn't grow EXPECT_EQ(Map.getNumBuckets(), NumBuckets); } |