llvm.org GIT mirror llvm / ff9b231
Improve StringMap unittests: reintroduce move count, but shield against std::pair internals From: Mehdi Amini <mehdi.amini@apple.com> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264418 91177308-0d34-0410-b5e6-96231b3b80d8 Mehdi Amini 3 years ago
1 changed file(s) with 12 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
390390 for (auto Size : {1, 32, 67}) {
391391 StringMap Map(Size);
392392 auto NumBuckets = Map.getNumBuckets();
393
394 // Prepare the elts in a vector. We do this as a pre-step to shield us
395 // against the internals of std::pair which can introduce spurious move/copy
396 std::vector> Elts;
397 for (int i = 0; i < Size; ++i)
398 Elts.emplace_back(Twine(i).str(), CountCtorCopyAndMove());
399
393400 CountCtorCopyAndMove::Move = 0;
394401 CountCtorCopyAndMove::Copy = 0;
395402 for (int i = 0; i < Size; ++i)
396 Map.insert(std::make_pair(Twine(i).str(), CountCtorCopyAndMove()));
397 // This relies on move-construction elision, and cannot be reliably tested.
398 // EXPECT_EQ((unsigned)Size * 3, CountCtorCopyAndMove::Move);
399 // No copy is expected.
400 EXPECT_EQ(0u, CountCtorCopyAndMove::Copy);
403 Map.insert(Elts[i]);
404 // After the inital copy, the map will move the Elts in the Entry.
405 EXPECT_EQ((unsigned)Size, CountCtorCopyAndMove::Move);
406 // We copy once the pair from the Elts vector
407 EXPECT_EQ((unsigned)Size, CountCtorCopyAndMove::Copy);
401408 // Check that the map didn't grow
402409 EXPECT_EQ(Map.getNumBuckets(), NumBuckets);
403410 }