1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-21 22:54:16 +01:00

[util] Add move & copy constructors to small_vector

This commit is contained in:
Robin Kertels 2024-03-13 15:49:01 +01:00 committed by Joshie
parent ab12ffa0da
commit 7de88ff993

View File

@ -13,8 +13,37 @@ namespace dxvk {
small_vector() { } small_vector() { }
small_vector (const small_vector&) = delete; small_vector(const small_vector& other) {
small_vector& operator = (const small_vector&) = delete; reserve(other.m_size);
for (size_t i = 0; i < other.m_size; i++) {
*ptr(i) = *other.ptr(i);
}
m_size = other.m_size;
};
small_vector& operator = (const small_vector& other) {
for (size_t i = 0; i < m_size; i++)
ptr(i)->~T();
reserve(other.m_size);
for (size_t i = 0; i < other.m_size; i++) {
*ptr(i) = *other.ptr(i);
}
m_size = other.m_size;
};
small_vector(small_vector&& other) {
if (other.m_capacity == N) {
for (size_t i = 0; i < other.m_size; i++) {
u.m_data[i] = std::move(other.u.m_data[i]);
}
} else {
u.m_ptr = other.u.m_ptr;
other.m_capacity = N;
}
m_size = other.m_size;
other.m_size = 0;
}
~small_vector() { ~small_vector() {
for (size_t i = 0; i < m_size; i++) for (size_t i = 0; i < m_size; i++)
@ -23,7 +52,7 @@ namespace dxvk {
if (m_capacity > N) if (m_capacity > N)
delete[] u.m_ptr; delete[] u.m_ptr;
} }
size_t size() const { size_t size() const {
return m_size; return m_size;
} }
@ -43,7 +72,7 @@ namespace dxvk {
if (m_capacity > N) if (m_capacity > N)
delete[] u.m_ptr; delete[] u.m_ptr;
m_capacity = n; m_capacity = n;
u.m_ptr = data; u.m_ptr = data;
} }
@ -56,7 +85,7 @@ namespace dxvk {
for (size_t i = n; i < m_size; i++) for (size_t i = n; i < m_size; i++)
ptr(i)->~T(); ptr(i)->~T();
for (size_t i = m_size; i < n; i++) for (size_t i = m_size; i < n; i++)
new (ptr(i)) T(); new (ptr(i)) T();