From: Owen Anderson Date: Tue, 11 Sep 2007 05:08:05 +0000 (+0000) Subject: Add a ValueInfoT template parameter to DenseMap so that it can properly make decisions X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=29ce95511f905df3a63e3b953a4a0179ead46865;p=oota-llvm.git Add a ValueInfoT template parameter to DenseMap so that it can properly make decisions based on whether the key AND the value require ctors/dtors. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41837 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ADT/DenseMap.h b/include/llvm/ADT/DenseMap.h index 43382492856..82cf5229e8b 100644 --- a/include/llvm/ADT/DenseMap.h +++ b/include/llvm/ADT/DenseMap.h @@ -41,15 +41,29 @@ struct DenseMapKeyInfo { static bool isPod() { return true; } }; +template +struct DenseMapValueInfo { + //static bool isPod() +}; + +// Provide DenseMapValueInfo for all pointers. +template +struct DenseMapValueInfo { + static bool isPod() { return true; } +}; + template > + typename KeyInfoT = DenseMapKeyInfo, + typename ValueInfoT = DenseMapValueInfo > class DenseMapIterator; template > + typename KeyInfoT = DenseMapKeyInfo, + typename ValueInfoT = DenseMapValueInfo > class DenseMapConstIterator; template > + typename KeyInfoT = DenseMapKeyInfo, + typename ValueInfoT = DenseMapValueInfo > class DenseMap { typedef std::pair BucketT; unsigned NumBuckets; @@ -181,7 +195,7 @@ public: private: void CopyFrom(const DenseMap& other) { - if (NumBuckets != 0 && !KeyInfoT::isPod()) { + if (NumBuckets != 0 && (!KeyInfoT::isPod() || !ValueInfoT::isPod())) { const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey(); for (BucketT *P = Buckets, *E = Buckets+NumBuckets; P != E; ++P) { if (P->first != EmptyKey && P->first != TombstoneKey) @@ -198,13 +212,13 @@ private: Buckets = reinterpret_cast(new char[sizeof(BucketT) * other.NumBuckets]); - if (KeyInfoT::isPod()) + if (KeyInfoT::isPod() && ValueInfoT::isPod()) memcpy(Buckets, other.Buckets, other.NumBuckets * sizeof(BucketT)); else for (size_t i = 0; i < other.NumBuckets; ++i) { new (Buckets[i].first) KeyT(other.Buckets[i].first); if (Buckets[i].first != getEmptyKey() && - Buckets[i].first != getTombstoneKey()) + Buckets[i].first != getTombstoneKey()) new (Buckets[i].second) ValueT(other.Buckets[i].second); } NumBuckets = other.NumBuckets; @@ -373,7 +387,7 @@ private: } }; -template +template class DenseMapIterator { typedef std::pair BucketT; protected: @@ -416,7 +430,7 @@ private: } }; -template +template class DenseMapConstIterator : public DenseMapIterator { public: DenseMapConstIterator(const std::pair *Pos,