diff options
-rw-r--r-- | llvm/include/llvm/ADT/DenseMap.h | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h index 7535eb2..68498a3 100644 --- a/llvm/include/llvm/ADT/DenseMap.h +++ b/llvm/include/llvm/ADT/DenseMap.h @@ -471,19 +471,23 @@ protected: setNumEntries(other.getNumEntries()); setNumTombstones(other.getNumTombstones()); - if (std::is_trivially_copyable<KeyT>::value && - std::is_trivially_copyable<ValueT>::value) - memcpy(reinterpret_cast<void *>(getBuckets()), other.getBuckets(), - getNumBuckets() * sizeof(BucketT)); - else - for (size_t i = 0; i < getNumBuckets(); ++i) { - ::new (&getBuckets()[i].getFirst()) - KeyT(other.getBuckets()[i].getFirst()); - if (!KeyInfoT::isEqual(getBuckets()[i].getFirst(), getEmptyKey()) && - !KeyInfoT::isEqual(getBuckets()[i].getFirst(), getTombstoneKey())) - ::new (&getBuckets()[i].getSecond()) - ValueT(other.getBuckets()[i].getSecond()); + BucketT *Buckets = getBuckets(); + const BucketT *OtherBuckets = other.getBuckets(); + const size_t NumBuckets = getNumBuckets(); + if constexpr (std::is_trivially_copyable_v<KeyT> && + std::is_trivially_copyable_v<ValueT>) { + memcpy(reinterpret_cast<void *>(Buckets), OtherBuckets, + NumBuckets * sizeof(BucketT)); + } else { + const KeyT EmptyKey = getEmptyKey(); + const KeyT TombstoneKey = getTombstoneKey(); + for (size_t I = 0; I < NumBuckets; ++I) { + ::new (&Buckets[I].getFirst()) KeyT(OtherBuckets[I].getFirst()); + if (!KeyInfoT::isEqual(Buckets[I].getFirst(), EmptyKey) && + !KeyInfoT::isEqual(Buckets[I].getFirst(), TombstoneKey)) + ::new (&Buckets[I].getSecond()) ValueT(OtherBuckets[I].getSecond()); } + } } static unsigned getHashValue(const KeyT &Val) { @@ -496,7 +500,7 @@ protected: } static const KeyT getEmptyKey() { - static_assert(std::is_base_of<DenseMapBase, DerivedT>::value, + static_assert(std::is_base_of_v<DenseMapBase, DerivedT>, "Must pass the derived type to this template!"); return KeyInfoT::getEmptyKey(); } |