diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-05-27 17:38:18 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-05-27 17:38:18 +0000 |
commit | 295d8ff007ef2c36a91141d7f7aa218f43c4c4b5 (patch) | |
tree | 73c589a4e1b7ce61f001b089b5b7f633d46b6fa6 | |
parent | b4654c1c490275370ca706eed2d85cc232b21155 (diff) |
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
-rw-r--r-- | include/llvm/ADT/DenseMap.h | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/include/llvm/ADT/DenseMap.h b/include/llvm/ADT/DenseMap.h index f7ae346253..4b0df5d371 100644 --- a/include/llvm/ADT/DenseMap.h +++ b/include/llvm/ADT/DenseMap.h @@ -62,20 +62,9 @@ public: 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 @@ public: 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) { |