[llvm-commits] [llvm] r157538 - /llvm/trunk/include/llvm/ADT/DenseMap.h

Benjamin Kramer benny.kra at googlemail.com
Sun May 27 10:38:18 PDT 2012


Author: d0k
Date: Sun May 27 12:38:18 2012
New Revision: 157538

URL: http://llvm.org/viewvc/llvm-project?rev=157538&view=rev
Log:
DenseMap: Factor destruction into a common helper method.

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

Modified: llvm/trunk/include/llvm/ADT/DenseMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/DenseMap.h?rev=157538&r1=157537&r2=157538&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/DenseMap.h (original)
+++ llvm/trunk/include/llvm/ADT/DenseMap.h Sun May 27 12:38:18 2012
@@ -62,20 +62,9 @@
     init(NextPowerOf2(std::distance(I, E)));
     insert(I, E);
   }
-  
+
   ~DenseMap() {
-    const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey();
-    for (BucketT *P = Buckets, *E = Buckets+NumBuckets; P != E; ++P) {
-      if (!KeyInfoT::isEqual(P->first, EmptyKey) &&
-          !KeyInfoT::isEqual(P->first, TombstoneKey))
-        P->second.~ValueT();
-      P->first.~KeyT();
-    }
-#ifndef NDEBUG
-    if (NumBuckets)
-      memset((void*)Buckets, 0x5a, sizeof(BucketT)*NumBuckets);
-#endif
-    operator delete(Buckets);
+    DestroyAll();
   }
 
   typedef DenseMapIterator<KeyT, ValueT, KeyInfoT> iterator;
@@ -254,28 +243,28 @@
   const void *getPointerIntoBucketsArray() const { return Buckets; }
 
 private:
-  void CopyFrom(const DenseMap& other) {
-    if (NumBuckets != 0 &&
-        (!isPodLike<KeyT>::value || !isPodLike<ValueT>::value)) {
-      const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey();
-      for (BucketT *P = Buckets, *E = Buckets+NumBuckets; P != E; ++P) {
-        if (!KeyInfoT::isEqual(P->first, EmptyKey) &&
-            !KeyInfoT::isEqual(P->first, TombstoneKey))
-          P->second.~ValueT();
-        P->first.~KeyT();
-      }
+  void DestroyAll() {
+    const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey();
+    for (BucketT *P = Buckets, *E = Buckets+NumBuckets; P != E; ++P) {
+      if (!KeyInfoT::isEqual(P->first, EmptyKey) &&
+          !KeyInfoT::isEqual(P->first, TombstoneKey))
+        P->second.~ValueT();
+      P->first.~KeyT();
     }
 
-    NumEntries = other.NumEntries;
-    NumTombstones = other.NumTombstones;
-
     if (NumBuckets) {
 #ifndef NDEBUG
       memset((void*)Buckets, 0x5a, sizeof(BucketT)*NumBuckets);
 #endif
       operator delete(Buckets);
     }
+  }
 
+  void CopyFrom(const DenseMap& other) {
+    DestroyAll();
+
+    NumEntries = other.NumEntries;
+    NumTombstones = other.NumTombstones;
     NumBuckets = other.NumBuckets;
 
     if (NumBuckets == 0) {





More information about the llvm-commits mailing list