llvm.org GIT mirror llvm / 29ce955
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 Owen Anderson 12 years ago
1 changed file(s) with 22 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
4040 static bool isPod() { return true; }
4141 };
4242
43 template
44 struct DenseMapValueInfo {
45 //static bool isPod()
46 };
47
48 // Provide DenseMapValueInfo for all pointers.
49 template
50 struct DenseMapValueInfo {
51 static bool isPod() { return true; }
52 };
53
4354 template
44 typename KeyInfoT = DenseMapKeyInfo >
55 typename KeyInfoT = DenseMapKeyInfo,
56 typename ValueInfoT = DenseMapValueInfo >
4557 class DenseMapIterator;
4658 template
47 typename KeyInfoT = DenseMapKeyInfo >
59 typename KeyInfoT = DenseMapKeyInfo,
60 typename ValueInfoT = DenseMapValueInfo >
4861 class DenseMapConstIterator;
4962
5063 template
51 typename KeyInfoT = DenseMapKeyInfo >
64 typename KeyInfoT = DenseMapKeyInfo,
65 typename ValueInfoT = DenseMapValueInfo >
5266 class DenseMap {
5367 typedef std::pair BucketT;
5468 unsigned NumBuckets;
180194
181195 private:
182196 void CopyFrom(const DenseMap& other) {
183 if (NumBuckets != 0 && !KeyInfoT::isPod()) {
197 if (NumBuckets != 0 && (!KeyInfoT::isPod() || !ValueInfoT::isPod())) {
184198 const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey();
185199 for (BucketT *P = Buckets, *E = Buckets+NumBuckets; P != E; ++P) {
186200 if (P->first != EmptyKey && P->first != TombstoneKey)
197211 Buckets = reinterpret_cast(new char[sizeof(BucketT) *
198212 other.NumBuckets]);
199213
200 if (KeyInfoT::isPod())
214 if (KeyInfoT::isPod() && ValueInfoT::isPod())
201215 memcpy(Buckets, other.Buckets, other.NumBuckets * sizeof(BucketT));
202216 else
203217 for (size_t i = 0; i < other.NumBuckets; ++i) {
204218 new (Buckets[i].first) KeyT(other.Buckets[i].first);
205219 if (Buckets[i].first != getEmptyKey() &&
206 Buckets[i].first != getTombstoneKey())
220 Buckets[i].first != getTombstoneKey())
207221 new (Buckets[i].second) ValueT(other.Buckets[i].second);
208222 }
209223 NumBuckets = other.NumBuckets;
372386 }
373387 };
374388
375 template>
389 template, typename ValueInfoT>
376390 class DenseMapIterator {
377391 typedef std::pair BucketT;
378392 protected:
415429 }
416430 };
417431
418 template>
432 template, typename ValueInfoT>
419433 class DenseMapConstIterator : public DenseMapIterator {
420434 public:
421435 DenseMapConstIterator(const std::pair *Pos,