From: David Wells Date: Sat, 7 Dec 2024 22:22:10 +0000 (-0500) Subject: AlignedVector::resize_fast(): use is_trivially_default_constructible. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ddc4e67dc43e4a59454214b840ed5b58e042bfbd;p=dealii.git AlignedVector::resize_fast(): use is_trivially_default_constructible. Trivial default constructors are no-ops so we can omit them in this case. One such class in deal.II is VectorizedArray. --- diff --git a/include/deal.II/base/aligned_vector.h b/include/deal.II/base/aligned_vector.h index 633d8ee45f..b976df0829 100644 --- a/include/deal.II/base/aligned_vector.h +++ b/include/deal.II/base/aligned_vector.h @@ -134,23 +134,20 @@ public: operator=(AlignedVector &&vec) noexcept; /** - * Change the size of the vector. If the new size is larger than the - * previous size, then new elements will be added to the end of the - * vector; these elements will remain uninitialized (i.e., left in - * an undefined state) if `std::is_trivial` is `true`, and - * will be default initialized if `std::is_trivial` is `false`. - * See [here](https://en.cppreference.com/w/cpp/types/is_trivial) for - * a definition of what `std::is_trivial` does. + * Change the size of the vector. If the new size is larger than the previous + * size, then new elements will be added to the end of the vector; these + * elements will remain uninitialized (i.e., left in an undefined state) if + * `std::is_trivially_default_constructible_v` is `true`, and will be + * default initialized if that type trait is `false`. See + * [here](https://en.cppreference.com/w/cpp/types/is_default_constructible) + * for a precise definition of `std::is_trivially_default_constructible`. * - * If the new size is less than the previous size, then the last few - * elements will be destroyed if `std::is_trivial` will be `false` - * or will simply be ignored in the future if - * `std::is_trivial` is `true`. + * If the new size is less than the previous size, then the `new_size`th and + * all subsequent elements will be destroyed. * - * As a consequence of the outline above, the "_fast" suffix of this - * function refers to the fact that for "trivial" classes `T`, this - * function omits constructor/destructor calls and in particular the - * initialization of new elements. + * As a consequence of the outline above, the "_fast" suffix of this function + * refers to the fact that for trivially default constructible types `T`, this + * function omits the initialization of new elements. * * @note This method can only be invoked for classes @p T that define a * default constructor, @p T(). Otherwise, compilation will fail. @@ -1356,9 +1353,9 @@ AlignedVector::resize_fast(const size_type new_size) reserve(new_size); used_elements_end = elements.get() + new_size; - // need to still set the values in case the class is non-trivial because - // virtual classes etc. need to run their (default) constructor - if (std::is_trivial_v == false) + // Leave the new array entries as-is (with undefined values) unless T's + // default constructor is nontrivial (i.e., it is not a no-op) + if (std::is_trivially_default_constructible_v == false) dealii::internal::AlignedVectorDefaultInitialize( new_size - old_size, elements.get() + old_size); }