[llvm-commits] [llvm] r53009 - /llvm/trunk/include/llvm/ADT/StringMap.h

Chris Lattner sabre at nondot.org
Tue Jul 1 22:30:45 PDT 2008


Author: lattner
Date: Wed Jul  2 00:30:45 2008
New Revision: 53009

URL: http://llvm.org/viewvc/llvm-project?rev=53009&view=rev
Log:
optimize StringMap::clear

Modified:
    llvm/trunk/include/llvm/ADT/StringMap.h

Modified: llvm/trunk/include/llvm/ADT/StringMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringMap.h?rev=53009&r1=53008&r2=53009&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/StringMap.h (original)
+++ llvm/trunk/include/llvm/ADT/StringMap.h Wed Jul  2 00:30:45 2008
@@ -335,8 +335,16 @@
 
   // clear - Empties out the StringMap
   void clear() {
-    while (!empty())
-      erase(begin());
+    if (empty()) return;
+    
+    // Zap all values, resetting the keys back to non-present (not tombstone),
+    // which is safe because we're removing all elements.
+    for (ItemBucket *I = TheTable, *E = TheTable+NumBuckets; I != E; ++I) {
+      if (I->Item && I->Item != getTombstoneVal()) {
+        static_cast<MapEntryTy*>(I->Item)->Destroy(Allocator);
+        I->Item = 0;
+      }
+    }
   }
 
   /// GetOrCreateValue - Look up the specified key in the table.  If a value
@@ -398,10 +406,7 @@
   }
 
   ~StringMap() {
-    for (ItemBucket *I = TheTable, *E = TheTable+NumBuckets; I != E; ++I) {
-      if (I->Item && I->Item != getTombstoneVal())
-        static_cast<MapEntryTy*>(I->Item)->Destroy(Allocator);
-    }
+    clear();
     free(TheTable);
   }
 private:





More information about the llvm-commits mailing list