Don't resize util::array if size didn't change

This commit is contained in:
Nikita Lisitsa 2022-05-23 20:25:44 +03:00
parent 1af6f26e80
commit 1b075bf40c

View file

@ -383,6 +383,9 @@ namespace psemek::util
template <typename T, std::size_t N>
void array<T, N>::resize(dims_type const & dims)
{
if (dims == dims_)
return;
std::unique_ptr<T[]> data(new T[detail::product(dims)]);
resize_impl(std::move(data), dims);
}
@ -390,6 +393,9 @@ namespace psemek::util
template <typename T, std::size_t N>
void array<T, N>::resize(dims_type const & dims, T const & value)
{
if (dims == dims_)
return;
auto const size = detail::product(dims);
std::unique_ptr<T[]> data(new T[size]);
std::fill(data.get(), data.get() + size, value);