From 22f08f83c5ae8355feb58813999b293c75051a2e Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Mon, 8 Nov 2021 02:25:51 -0600 Subject: [PATCH] [ox/std] Rename Vector alloc and dealloc methods --- deps/ox/src/ox/std/vector.hpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/deps/ox/src/ox/std/vector.hpp b/deps/ox/src/ox/std/vector.hpp index 07d9752b..cde3d93c 100644 --- a/deps/ox/src/ox/std/vector.hpp +++ b/deps/ox/src/ox/std/vector.hpp @@ -32,7 +32,7 @@ struct SmallVector { SmallVector(SmallVector&) noexcept = default; SmallVector(SmallVector&&) noexcept = default; protected: - constexpr void initItems(T **items, std::size_t cap) noexcept { + constexpr void allocate(T **items, std::size_t cap) noexcept { if (cap <= Size) { *items = reinterpret_cast(m_data); } else { @@ -62,9 +62,9 @@ struct SmallVector { } } - constexpr void clearItems(T *items, std::size_t n) noexcept { - if (static_cast(items) != static_cast(m_data)) { - m_allocator.deallocate(items, n); + constexpr void deallocate(T *items, std::size_t cap) noexcept { + if (items && static_cast(items) != static_cast(m_data)) { + m_allocator.deallocate(items, cap); } } @@ -79,7 +79,7 @@ struct SmallVector { SmallVector(SmallVector&) noexcept = default; SmallVector(SmallVector&&) noexcept = default; protected: - constexpr void initItems(T **items, std::size_t cap) noexcept { + constexpr void allocate(T **items, std::size_t cap) noexcept { *items = m_allocator.allocate(cap); } @@ -91,8 +91,10 @@ struct SmallVector { constexpr void moveItemsFrom(T**, SmallVector&, const std::size_t, const std::size_t) noexcept { } - constexpr void clearItems(T *items, std::size_t n) noexcept { - m_allocator.deallocate(items, n); + constexpr void deallocate(T *items, std::size_t cap) noexcept { + if (items) { + m_allocator.deallocate(items, cap); + } } }; @@ -349,7 +351,7 @@ template constexpr Vector::Vector(std::size_t size) noexcept { m_size = size; m_cap = m_size; - this->initItems(&m_items, m_cap); + this->allocate(&m_items, m_cap); for (std::size_t i = 0; i < size; ++i) { m_items[i] = {}; } @@ -366,7 +368,7 @@ template constexpr Vector::Vector(const Vector &other) { m_size = other.m_size; m_cap = other.m_cap; - this->initItems(&m_items, other.m_cap); + this->allocate(&m_items, other.m_cap); for (std::size_t i = 0; i < m_size; ++i) { new (&m_items[i]) T(other.m_items[i]); } @@ -386,7 +388,7 @@ constexpr Vector::Vector(Vector &&other) noexcept { template Vector::~Vector() { clear(); - this->clearItems(m_items, m_cap); + this->deallocate(m_items, m_cap); m_items = nullptr; } @@ -407,11 +409,11 @@ template constexpr Vector &Vector::operator=(const Vector &other) { if (this != &other) { clear(); - this->clearItems(m_items, m_cap); + this->deallocate(m_items, m_cap); m_items = nullptr; m_size = other.m_size; m_cap = other.m_cap; - this->initItems(&m_items, other.m_cap); + this->allocate(&m_items, other.m_cap); for (std::size_t i = 0; i < m_size; i++) { m_items[i] = other.m_items[i]; } @@ -423,7 +425,7 @@ template constexpr Vector &Vector::operator=(Vector &&other) noexcept { if (this != &other) { clear(); - this->clearItems(m_items, m_cap); + this->deallocate(m_items, m_cap); m_size = other.m_size; m_cap = other.m_cap; m_items = other.m_items; @@ -599,7 +601,7 @@ template constexpr void Vector::expandCap(std::size_t cap) { auto oldItems = m_items; m_cap = cap; - this->initItems(&m_items, cap); + this->allocate(&m_items, cap); if (oldItems) { // move over old items const auto itRange = cap > m_size ? m_size : cap; for (std::size_t i = 0; i < itRange; i++) { @@ -608,7 +610,7 @@ constexpr void Vector::expandCap(std::size_t cap) { for (std::size_t i = itRange; i < m_cap; i++) { new (&m_items[i]) T; } - this->clearItems(m_items, m_cap); + this->deallocate(oldItems, m_cap); } }