[llvm-commits] [llvm] r41837 - /llvm/trunk/include/llvm/ADT/DenseMap.h
Owen Anderson
resistor at mac.com
Mon Sep 10 22:08:05 PDT 2007
Author: resistor
Date: Tue Sep 11 00:08:05 2007
New Revision: 41837
URL: http://llvm.org/viewvc/llvm-project?rev=41837&view=rev
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.
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,
More information about the llvm-commits
mailing list