From: David Wells Date: Sat, 7 Dec 2024 22:45:08 +0000 (-0500) Subject: AlignedVector: Switch to placement new in two codepaths. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e797e18c77154b9d779c11cefd7fe073bc96b2ec;p=dealii.git AlignedVector: Switch to placement new in two codepaths. Using placement new here is, for scalar types, the same as assignment. For non-scalar types, this change results in fewer operations since instead of doing default construction followed by assignment we now just use the copy constructor. --- diff --git a/include/deal.II/base/aligned_vector.h b/include/deal.II/base/aligned_vector.h index 4ee1522094..973277db05 100644 --- a/include/deal.II/base/aligned_vector.h +++ b/include/deal.II/base/aligned_vector.h @@ -1542,10 +1542,7 @@ AlignedVector::push_back(const T in_data) Assert(used_elements_end <= allocated_elements_end, ExcInternalError()); if (used_elements_end == allocated_elements_end) reserve(std::max(2 * capacity(), static_cast(16))); - if (std::is_trivial_v == false) - new (used_elements_end++) T(in_data); - else - *used_elements_end++ = in_data; + new (used_elements_end++) T(in_data); } @@ -1580,11 +1577,7 @@ AlignedVector::insert_back(ForwardIterator begin, ForwardIterator end) const size_type old_size = size(); reserve(old_size + (end - begin)); for (; begin != end; ++begin, ++used_elements_end) - { - if (std::is_trivial_v == false) - new (used_elements_end) T; - *used_elements_end = *begin; - } + new (used_elements_end) T(*begin); }