diff --git a/libluna/include/luna/Vector.h b/libluna/include/luna/Vector.h index 9678a2d4..c008ddc4 100644 --- a/libluna/include/luna/Vector.h +++ b/libluna/include/luna/Vector.h @@ -36,13 +36,10 @@ template class Vector { if (&other == this) return *this; - if (m_data) free_impl(m_data); - - m_data = nullptr; - m_capacity = m_size = 0; + if (m_data) clear(); reserve(other.capacity()); - memcpy(m_data, other.data(), other.size()); + for (usize i = 0; i < other.size(); i++) { new (&m_data[i]) T(other.m_data[i]); } m_size = other.size(); return *this; @@ -52,7 +49,7 @@ template class Vector { if (&other == this) return *this; - if (m_data) free_impl(m_data); + if (m_data) clear(); m_data = other.data(); m_capacity = other.capacity(); @@ -66,11 +63,7 @@ template class Vector ~Vector() { - if (m_data) - { - for (const T& item : *this) { item.~T(); } - free_impl(m_data); - } + if (m_data) { clear(); } } Result try_reserve(usize capacity)