From: Wolfgang Bangerth Date: Mon, 5 Apr 2021 21:28:38 +0000 (-0600) Subject: Slightly simplify the AlignedVector::reserve() function. X-Git-Tag: v9.3.0-rc1~238^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=defafd4f711402ca9504e0982ec6ea785d80825e;p=dealii.git Slightly simplify the AlignedVector::reserve() function. --- 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); });