DenseMap: Factor destruction into a common helper method.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157538 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2012-05-27 17:38:18 +00:00
parent b4654c1c49
commit 295d8ff007

View File

@ -64,18 +64,7 @@ public:
} }
~DenseMap() { ~DenseMap() {
const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey(); DestroyAll();
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);
} }
typedef DenseMapIterator<KeyT, ValueT, KeyInfoT> iterator; typedef DenseMapIterator<KeyT, ValueT, KeyInfoT> iterator;
@ -254,28 +243,28 @@ public:
const void *getPointerIntoBucketsArray() const { return Buckets; } const void *getPointerIntoBucketsArray() const { return Buckets; }
private: private:
void CopyFrom(const DenseMap& other) { void DestroyAll() {
if (NumBuckets != 0 && const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey();
(!isPodLike<KeyT>::value || !isPodLike<ValueT>::value)) { for (BucketT *P = Buckets, *E = Buckets+NumBuckets; P != E; ++P) {
const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey(); if (!KeyInfoT::isEqual(P->first, EmptyKey) &&
for (BucketT *P = Buckets, *E = Buckets+NumBuckets; P != E; ++P) { !KeyInfoT::isEqual(P->first, TombstoneKey))
if (!KeyInfoT::isEqual(P->first, EmptyKey) && P->second.~ValueT();
!KeyInfoT::isEqual(P->first, TombstoneKey)) P->first.~KeyT();
P->second.~ValueT();
P->first.~KeyT();
}
} }
NumEntries = other.NumEntries;
NumTombstones = other.NumTombstones;
if (NumBuckets) { if (NumBuckets) {
#ifndef NDEBUG #ifndef NDEBUG
memset((void*)Buckets, 0x5a, sizeof(BucketT)*NumBuckets); memset((void*)Buckets, 0x5a, sizeof(BucketT)*NumBuckets);
#endif #endif
operator delete(Buckets); operator delete(Buckets);
} }
}
void CopyFrom(const DenseMap& other) {
DestroyAll();
NumEntries = other.NumEntries;
NumTombstones = other.NumTombstones;
NumBuckets = other.NumBuckets; NumBuckets = other.NumBuckets;
if (NumBuckets == 0) { if (NumBuckets == 0) {