From: Wolfgang Bangerth Date: Tue, 11 May 2021 21:40:37 +0000 (-0600) Subject: Simplify some code in AlignedVector. X-Git-Tag: v9.3.0-rc1~89^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F12186%2Fhead;p=dealii.git Simplify some code in AlignedVector. --- diff --git a/include/deal.II/base/aligned_vector.h b/include/deal.II/base/aligned_vector.h index 5859fe76ae..aa52ee7396 100644 --- a/include/deal.II/base/aligned_vector.h +++ b/include/deal.II/base/aligned_vector.h @@ -930,16 +930,13 @@ AlignedVector::resize_fast(const size_type new_size) {} // nothing to do here else if (new_size < old_size) { - // call destructor on fields that are released. doing it backward - // releases the elements in reverse order as compared to how they were - // created + // call destructor on fields that are released, if the type requires it. + // doing it backward releases the elements in reverse order as compared to + // how they were created if (std::is_trivial::value == false) - { - while (used_elements_end != elements.get() + new_size) - (--used_elements_end)->~T(); - } - else - used_elements_end = elements.get() + new_size; + for (T *p = used_elements_end - 1; p >= elements.get() + new_size; --p) + p->~T(); + used_elements_end = elements.get() + new_size; } else // new_size > old_size { @@ -969,16 +966,13 @@ AlignedVector::resize(const size_type new_size) {} // nothing to do here else if (new_size < old_size) { - // call destructor on fields that are released. doing it backward - // releases the elements in reverse order as compared to how they were - // created + // call destructor on fields that are released, if the type requires it. + // doing it backward releases the elements in reverse order as compared to + // how they were created if (std::is_trivial::value == false) - { - while (used_elements_end != elements.get() + new_size) - (--used_elements_end)->~T(); - } - else - used_elements_end = elements.get() + new_size; + for (T *p = used_elements_end - 1; p >= elements.get() + new_size; --p) + p->~T(); + used_elements_end = elements.get() + new_size; } else // new_size > old_size { @@ -1006,16 +1000,13 @@ AlignedVector::resize(const size_type new_size, const T &init) {} // nothing to do here else if (new_size < old_size) { - // call destructor on fields that are released. doing it backward - // releases the elements in reverse order as compared to how they were - // created + // call destructor on fields that are released, if the type requires it. + // doing it backward releases the elements in reverse order as compared to + // how they were created if (std::is_trivial::value == false) - { - while (used_elements_end != elements.get() + new_size) - (--used_elements_end)->~T(); - } - else - used_elements_end = elements.get() + new_size; + for (T *p = used_elements_end - 1; p >= elements.get() + new_size; --p) + p->~T(); + used_elements_end = elements.get() + new_size; } else // new_size > old_size {