When destroying a StringMap, just iterate over the map and destroy the contained...
authorPete Cooper <peter_cooper@apple.com>
Wed, 19 Mar 2014 00:23:30 +0000 (00:23 +0000)
committerPete Cooper <peter_cooper@apple.com>
Wed, 19 Mar 2014 00:23:30 +0000 (00:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204204 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/StringMap.h

index c48f1ead02363e81b8cdf0d2064397b80ec711c9..4e74cf6529e63b4d9977d37aa8197f70f40e926c 100644 (file)
@@ -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);
   }
 };