mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Avoid zero-sized allocations when copying a fresh DenseMap.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127110 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7cefa640de
commit
88b0c6a59a
@ -255,19 +255,25 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
operator delete(Buckets);
|
operator delete(Buckets);
|
||||||
}
|
}
|
||||||
Buckets = static_cast<BucketT*>(operator new(sizeof(BucketT) *
|
|
||||||
other.NumBuckets));
|
NumBuckets = other.NumBuckets;
|
||||||
|
|
||||||
|
if (NumBuckets == 0) {
|
||||||
|
Buckets = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Buckets = static_cast<BucketT*>(operator new(sizeof(BucketT) * NumBuckets));
|
||||||
|
|
||||||
if (isPodLike<KeyInfoT>::value && isPodLike<ValueInfoT>::value)
|
if (isPodLike<KeyInfoT>::value && isPodLike<ValueInfoT>::value)
|
||||||
memcpy(Buckets, other.Buckets, other.NumBuckets * sizeof(BucketT));
|
memcpy(Buckets, other.Buckets, NumBuckets * sizeof(BucketT));
|
||||||
else
|
else
|
||||||
for (size_t i = 0; i < other.NumBuckets; ++i) {
|
for (size_t i = 0; i < NumBuckets; ++i) {
|
||||||
new (&Buckets[i].first) KeyT(other.Buckets[i].first);
|
new (&Buckets[i].first) KeyT(other.Buckets[i].first);
|
||||||
if (!KeyInfoT::isEqual(Buckets[i].first, getEmptyKey()) &&
|
if (!KeyInfoT::isEqual(Buckets[i].first, getEmptyKey()) &&
|
||||||
!KeyInfoT::isEqual(Buckets[i].first, getTombstoneKey()))
|
!KeyInfoT::isEqual(Buckets[i].first, getTombstoneKey()))
|
||||||
new (&Buckets[i].second) ValueT(other.Buckets[i].second);
|
new (&Buckets[i].second) ValueT(other.Buckets[i].second);
|
||||||
}
|
}
|
||||||
NumBuckets = other.NumBuckets;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BucketT *InsertIntoBucket(const KeyT &Key, const ValueT &Value,
|
BucketT *InsertIntoBucket(const KeyT &Key, const ValueT &Value,
|
||||||
|
Loading…
Reference in New Issue
Block a user