> Log: > 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.
Ah, interesting :) How about renaming DenseMapKeyInfo/DenseMapValueInfo -> DenseMapInfo? Is there any reason to keep them separate? That will give you: > template<typename KeyT, typename ValueT, > + typename KeyInfoT = DenseMapInfo<KeyT>, > + typename ValueInfoT = DenseMapInfo<ValueT> > And mean that you don't have to provide specializations for both. -Chris > 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=41837&r1=41836&r2=41837&view=diff > > ====================================================================== > ======== > --- llvm/trunk/include/llvm/ADT/DenseMap.h (original) > +++ llvm/trunk/include/llvm/ADT/DenseMap.h Tue Sep 11 00:08:05 2007 > @@ -41,15 +41,29 @@ > static bool isPod() { return true; } > }; > > +template<typename T> > +struct DenseMapValueInfo { > + //static bool isPod() > +}; > + > +// Provide DenseMapValueInfo for all pointers. > +template<typename T> > +struct DenseMapValueInfo<T*> { > + static bool isPod() { return true; } > +}; > + > template<typename KeyT, typename ValueT, > - typename KeyInfoT = DenseMapKeyInfo<KeyT> > > + typename KeyInfoT = DenseMapKeyInfo<KeyT>, > + typename ValueInfoT = DenseMapValueInfo<ValueT> > > class DenseMapIterator; > template<typename KeyT, typename ValueT, > - typename KeyInfoT = DenseMapKeyInfo<KeyT> > > + typename KeyInfoT = DenseMapKeyInfo<KeyT>, > + typename ValueInfoT = DenseMapValueInfo<ValueT> > > class DenseMapConstIterator; > > template<typename KeyT, typename ValueT, > - typename KeyInfoT = DenseMapKeyInfo<KeyT> > > + typename KeyInfoT = DenseMapKeyInfo<KeyT>, > + typename ValueInfoT = DenseMapValueInfo<ValueT> > > class DenseMap { > typedef std::pair<KeyT, ValueT> BucketT; > unsigned NumBuckets; > @@ -181,7 +195,7 @@ > > 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 @@ > Buckets = reinterpret_cast<BucketT*>(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 @@ > } > }; > > -template<typename KeyT, typename ValueT, typename KeyInfoT> > +template<typename KeyT, typename ValueT, typename KeyInfoT, > typename ValueInfoT> > class DenseMapIterator { > typedef std::pair<KeyT, ValueT> BucketT; > protected: > @@ -416,7 +430,7 @@ > } > }; > > -template<typename KeyT, typename ValueT, typename KeyInfoT> > +template<typename KeyT, typename ValueT, typename KeyInfoT, > typename ValueInfoT> > class DenseMapConstIterator : public DenseMapIterator<KeyT, > ValueT, KeyInfoT> { > public: > DenseMapConstIterator(const std::pair<KeyT, ValueT> *Pos, > > > _______________________________________________ > llvm-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits _______________________________________________ llvm-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
