@@ -471,19 +471,23 @@ class DenseMapBase : public DebugEpochBase {
471
471
setNumEntries (other.getNumEntries ());
472
472
setNumTombstones (other.getNumTombstones ());
473
473
474
- if (std::is_trivially_copyable<KeyT>::value &&
475
- std::is_trivially_copyable<ValueT>::value)
476
- memcpy (reinterpret_cast <void *>(getBuckets ()), other.getBuckets (),
477
- getNumBuckets () * sizeof (BucketT));
478
- else
479
- for (size_t i = 0 ; i < getNumBuckets (); ++i) {
480
- ::new (&getBuckets ()[i].getFirst ())
481
- KeyT (other.getBuckets ()[i].getFirst ());
482
- if (!KeyInfoT::isEqual (getBuckets ()[i].getFirst (), getEmptyKey ()) &&
483
- !KeyInfoT::isEqual (getBuckets ()[i].getFirst (), getTombstoneKey ()))
484
- ::new (&getBuckets ()[i].getSecond ())
485
- ValueT (other.getBuckets ()[i].getSecond ());
474
+ BucketT *Buckets = getBuckets ();
475
+ const BucketT *OtherBuckets = other.getBuckets ();
476
+ const size_t NumBuckets = getNumBuckets ();
477
+ if constexpr (std::is_trivially_copyable_v<KeyT> &&
478
+ std::is_trivially_copyable_v<ValueT>) {
479
+ memcpy (reinterpret_cast <void *>(Buckets), OtherBuckets,
480
+ NumBuckets * sizeof (BucketT));
481
+ } else {
482
+ const KeyT EmptyKey = getEmptyKey ();
483
+ const KeyT TombstoneKey = getTombstoneKey ();
484
+ for (size_t I = 0 ; I < NumBuckets; ++I) {
485
+ ::new (&Buckets[I].getFirst ()) KeyT (OtherBuckets[I].getFirst ());
486
+ if (!KeyInfoT::isEqual (Buckets[I].getFirst (), EmptyKey) &&
487
+ !KeyInfoT::isEqual (Buckets[I].getFirst (), TombstoneKey))
488
+ ::new (&Buckets[I].getSecond ()) ValueT (OtherBuckets[I].getSecond ());
486
489
}
490
+ }
487
491
}
488
492
489
493
static unsigned getHashValue (const KeyT &Val) {
@@ -496,7 +500,7 @@ class DenseMapBase : public DebugEpochBase {
496
500
}
497
501
498
502
static const KeyT getEmptyKey () {
499
- static_assert (std::is_base_of <DenseMapBase, DerivedT>::value ,
503
+ static_assert (std::is_base_of_v <DenseMapBase, DerivedT>,
500
504
" Must pass the derived type to this template!" );
501
505
return KeyInfoT::getEmptyKey ();
502
506
}
0 commit comments