]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Slightly simplify the AlignedVector::reserve() function.
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 5 Apr 2021 21:28:38 +0000 (15:28 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 6 Apr 2021 02:14:56 +0000 (20:14 -0600)
include/deal.II/base/aligned_vector.h

index 978f6e19b118d76b59842754873815e341511e91..8ae6af513ea36128ffcdc2047923dc531a463ebf 100644 (file)
@@ -899,17 +899,14 @@ AlignedVector<T>::reserve(const size_type new_allocated_size)
       // if we continuously increase the size of the vector, we might be
       // reallocating a lot of times. therefore, try to increase the size more
       // aggressively
-      size_type new_size = new_allocated_size;
-      if (new_allocated_size < (2 * old_allocated_size))
-        new_size = 2 * old_allocated_size;
-
-      const size_type size_actual_allocate = new_size * sizeof(T);
+      const size_type new_size =
+        std::max(new_allocated_size, 2 * old_allocated_size);
 
       // allocate and align along 64-byte boundaries (this is enough for all
       // levels of vectorization currently supported by deal.II)
       T *new_data_ptr;
       Utilities::System::posix_memalign(
-        reinterpret_cast<void **>(&new_data_ptr), 64, size_actual_allocate);
+        reinterpret_cast<void **>(&new_data_ptr), 64, new_size * sizeof(T));
       std::unique_ptr<T[], void (*)(T *)> new_data(new_data_ptr, [](T *ptr) {
         std::free(ptr);
       });

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.