[llvm] r204204 - When destroying a StringMap, just iterate over the map and destroy the contained elements. Don't reset them back to 0 as their values aren't needed any more. This results in ~StringMap() being mostly empty for POD types in BumpPtrAllocators

Pete Cooper peter_cooper at apple.com
Tue Mar 18 17:23:30 PDT 2014


Author: pete
Date: Tue Mar 18 19:23:30 2014
New Revision: 204204

URL: http://llvm.org/viewvc/llvm-project?rev=204204&view=rev
Log:
When destroying a StringMap, just iterate over the map and destroy the contained elements.  Don't reset them back to 0 as their values aren't needed any more.  This results in ~StringMap() being mostly empty for POD types in BumpPtrAllocators

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=204204&r1=204203&r2=204204&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringMap.h (original)
+++ llvm/trunk/include/llvm/ADT/StringMap.h Tue Mar 18 19:23:30 2014
@@ -387,7 +387,17 @@ public:
   }
 
   ~StringMap() {
-    clear();
+    // Delete all the elements in the map, but don't reset the elements
+    // to default values.  This is a copy of clear(), but avoids unnecessary
+    // work not required in the destructor.
+    if (!empty()) {
+      for (unsigned I = 0, E = NumBuckets; I != E; ++I) {
+        StringMapEntryBase *Bucket = TheTable[I];
+        if (Bucket && Bucket != getTombstoneVal()) {
+          static_cast<MapEntryTy*>(Bucket)->Destroy(Allocator);
+        }
+      }
+    }
     free(TheTable);
   }
 };





More information about the llvm-commits mailing list