From defafd4f711402ca9504e0982ec6ea785d80825e Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 5 Apr 2021 15:28:38 -0600 Subject: [PATCH] Slightly simplify the AlignedVector::reserve() function. --- include/deal.II/base/aligned_vector.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/include/deal.II/base/aligned_vector.h b/include/deal.II/base/aligned_vector.h index 978f6e19b1..8ae6af513e 100644 --- a/include/deal.II/base/aligned_vector.h +++ b/include/deal.II/base/aligned_vector.h @@ -899,17 +899,14 @@ AlignedVector::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(&new_data_ptr), 64, size_actual_allocate); + reinterpret_cast(&new_data_ptr), 64, new_size * sizeof(T)); std::unique_ptr new_data(new_data_ptr, [](T *ptr) { std::free(ptr); }); -- 2.39.5