From 2f9ce668797bcfb9ff442402109057b04ea28eb7 Mon Sep 17 00:00:00 2001 From: Robin Kertels Date: Thu, 19 Sep 2024 19:54:15 +0200 Subject: [PATCH] [util] Fix small_vector move constructor --- src/util/util_small_vector.h | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/util/util_small_vector.h b/src/util/util_small_vector.h index d96e58e02..27aa754b9 100644 --- a/src/util/util_small_vector.h +++ b/src/util/util_small_vector.h @@ -33,12 +33,36 @@ namespace dxvk { }; small_vector(small_vector&& other) { - if (other.m_capacity == N) { + if (other.m_size < N) { for (size_t i = 0; i < other.m_size; i++) { - u.m_data[i] = std::move(other.u.m_data[i]); + new (&u.m_data[i]) T(std::move(*other.ptr(i))); } } else { u.m_ptr = other.u.m_ptr; + m_capacity = other.m_capacity; + other.u.m_ptr = nullptr; + other.m_capacity = N; + } + m_size = other.m_size; + other.m_size = 0; + } + + small_vector& operator = (small_vector&& other) { + for (size_t i = 0; i < m_size; i++) + ptr(i)->~T(); + + if (m_capacity > N) + delete[] u.m_ptr; + + if (other.m_size < N) { + m_capacity = N; + for (size_t i = 0; i < other.m_size; i++) { + new (&u.m_data[i]) T(std::move(*other.ptr(i))); + } + } else { + u.m_ptr = other.u.m_ptr; + m_capacity = other.m_capacity; + other.u.m_ptr = nullptr; other.m_capacity = N; } m_size = other.m_size;