[llvm] r175538 - Remove my bogus MapVector::erase() with a narrower ::pop_back(), and add a unit test.

Douglas Gregor dgregor at apple.com
Tue Feb 19 10:26:07 PST 2013


Author: dgregor
Date: Tue Feb 19 12:26:07 2013
New Revision: 175538

URL: http://llvm.org/viewvc/llvm-project?rev=175538&view=rev
Log:
Remove my bogus MapVector::erase() with a narrower ::pop_back(), and add a unit test.

Modified:
    llvm/trunk/include/llvm/ADT/MapVector.h
    llvm/trunk/unittests/ADT/MapVectorTest.cpp

Modified: llvm/trunk/include/llvm/ADT/MapVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/MapVector.h?rev=175538&r1=175537&r2=175538&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/MapVector.h (original)
+++ llvm/trunk/include/llvm/ADT/MapVector.h Tue Feb 19 12:26:07 2013
@@ -119,14 +119,11 @@ public:
                             (Vector.begin() + Pos->second);
   }
 
-  /// \brief Erase entry with the given key.
-  void erase(const KeyT &key) {
-    typename MapType::iterator Pos = Map.find(key);
-    if (Pos == Map.end())
-      return;
-
-    Vector.erase(Vector.begin() + Pos->second);
+  /// \brief Remove the last element from the vector.
+  void pop_back() {
+    typename MapType::iterator Pos = Map.find(Vector.back().first);
     Map.erase(Pos);
+    Vector.pop_back();
   }
 };
 

Modified: llvm/trunk/unittests/ADT/MapVectorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/MapVectorTest.cpp?rev=175538&r1=175537&r2=175538&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/MapVectorTest.cpp (original)
+++ llvm/trunk/unittests/ADT/MapVectorTest.cpp Tue Feb 19 12:26:07 2013
@@ -13,7 +13,7 @@
 
 using namespace llvm;
 
-TEST(MapVectorTest, insert) {
+TEST(MapVectorTest, insert_pop) {
   MapVector<int, int> MV;
   std::pair<MapVector<int, int>::iterator, bool> R;
 
@@ -38,4 +38,18 @@ TEST(MapVectorTest, insert) {
   EXPECT_EQ(MV.size(), 2u);
   EXPECT_EQ(MV[1], 2);
   EXPECT_EQ(MV[4], 5);
+
+  MV.pop_back();
+  EXPECT_EQ(MV.size(), 1u);
+  EXPECT_EQ(MV[1], 2);
+
+  R = MV.insert(std::make_pair(4, 7));
+  ASSERT_NE(R.first, MV.end());
+  EXPECT_EQ(R.first->first, 4);
+  EXPECT_EQ(R.first->second, 7);
+  EXPECT_TRUE(R.second);  
+
+  EXPECT_EQ(MV.size(), 2u);
+  EXPECT_EQ(MV[1], 2);
+  EXPECT_EQ(MV[4], 7);
 }





More information about the llvm-commits mailing list