]> https://gitweb.dealii.org/ - dealii.git/commitdiff
AlignedVector: Switch to placement new in two codepaths. 17915/head
authorDavid Wells <drwells@email.unc.edu>
Sat, 7 Dec 2024 22:45:08 +0000 (17:45 -0500)
committerDavid Wells <drwells@email.unc.edu>
Sun, 8 Dec 2024 00:02:28 +0000 (19:02 -0500)
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.

include/deal.II/base/aligned_vector.h

index 4ee15220941036600e3530c640e530fb3806ecb9..973277db05136d1f2b3ede6db765656565b61bd3 100644 (file)
@@ -1542,10 +1542,7 @@ AlignedVector<T>::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<size_type>(16)));
-  if (std::is_trivial_v<T> == 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<T>::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<T> == false)
-        new (used_elements_end) T;
-      *used_elements_end = *begin;
-    }
+    new (used_elements_end) T(*begin);
 }
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.