@@ -548,7 +548,7 @@ template <class ElemTy> struct ConcurrentReadableArray {
548
548
auto newCapacity = std::max ((size_t )16 , count * 2 );
549
549
auto *newStorage = Storage::allocate (newCapacity);
550
550
if (storage) {
551
- std::copy (storage->data (), storage-> data () + count, newStorage->data ());
551
+ std::uninitialized_copy_n (storage->data (), count, newStorage->data ());
552
552
newStorage->Count .store (count, std::memory_order_release);
553
553
ConcurrentFreeListNode::add (&FreeList, storage);
554
554
}
@@ -622,10 +622,7 @@ using llvm::hash_value;
622
622
// / outstanding readers, but this won't destroy the static mutex it uses.
623
623
template <class ElemTy , class MutexTy = StaticMutex>
624
624
struct ConcurrentReadableHashMap {
625
- // We use memcpy and don't call destructors. Make sure the elements will put
626
- // up with this.
627
- static_assert (std::is_trivially_copyable<ElemTy>::value,
628
- " Elements must be trivially copyable." );
625
+ // We don't call destructors. Make sure the elements will put up with this.
629
626
static_assert (std::is_trivially_destructible<ElemTy>::value,
630
627
" Elements must not have destructors (they won't be called)." );
631
628
@@ -884,8 +881,13 @@ struct ConcurrentReadableHashMap {
884
881
auto *newElements = ElementStorage::allocate (newCapacity);
885
882
886
883
if (elements) {
887
- memcpy (newElements->data (), elements->data (),
888
- elementCount * sizeof (ElemTy));
884
+ if constexpr (std::is_trivially_copyable<ElemTy>::value) {
885
+ memcpy (newElements->data (), elements->data (),
886
+ elementCount * sizeof (ElemTy));
887
+ } else {
888
+ std::uninitialized_copy_n (elements->data (), elementCount,
889
+ newElements->data ());
890
+ }
889
891
ConcurrentFreeListNode::add (&FreeList, elements);
890
892
}
891
893
0 commit comments