Added ImmutableMap constructor that accepts a const TreeTy*.
[oota-llvm.git] / include / llvm / ADT / StringMap.h
index f180b363606067734c5bd6cf31611646521f234d..6675d04f8d0790d34be96af5429430081709a828 100644 (file)
@@ -333,6 +333,20 @@ public:
     return true;
   }
 
+  // clear - Empties out the StringMap
+  void clear() {
+    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
   /// exists, return it.  Otherwise, default construct a value, insert it, and
   /// return.
@@ -392,10 +406,7 @@ public:
   }
 
   ~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: