From 0e4bebcc3dbd0681280ea5ae49970d174ed9d15a Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 16 Feb 2022 02:28:00 -0600 Subject: [PATCH] [ox/std] Change initial Vector size to small vector size --- deps/ox/src/ox/std/vector.hpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/deps/ox/src/ox/std/vector.hpp b/deps/ox/src/ox/std/vector.hpp index 5f5a581f..30f5a24a 100644 --- a/deps/ox/src/ox/std/vector.hpp +++ b/deps/ox/src/ox/std/vector.hpp @@ -217,6 +217,7 @@ class Vector: detail::VectorAllocator { }; private: + static constexpr auto initialSize = SmallVectorSize > 0 ? SmallVectorSize : 50; std::size_t m_size = 0; std::size_t m_cap = 0; T *m_items = nullptr; @@ -242,42 +243,52 @@ class Vector: detail::VectorAllocator { return iterator<>(m_items, m_size, m_size); } + [[nodiscard]] constexpr iterator begin() const noexcept { return iterator(m_items, 0, m_size); } + [[nodiscard]] constexpr iterator end() const noexcept { return iterator(m_items, m_size, m_size); } + [[nodiscard]] constexpr iterator cbegin() const noexcept { return iterator(m_items, 0, m_size); } + [[nodiscard]] constexpr iterator cend() const noexcept { return iterator(m_items, m_size, m_size); } + [[nodiscard]] constexpr iterator rbegin() noexcept { return iterator(m_items, m_size - 1, m_size); } + [[nodiscard]] constexpr iterator rend() noexcept { return iterator(m_items, MaxValue, m_size); } + [[nodiscard]] constexpr iterator crbegin() const noexcept { return iterator(m_items, m_size - 1, m_size); } + [[nodiscard]] constexpr iterator crend() const noexcept { return iterator(m_items, MaxValue, m_size); } + [[nodiscard]] constexpr iterator rbegin() const noexcept { return iterator(m_items, m_size - 1, m_size); } + [[nodiscard]] constexpr iterator rend() const noexcept { return iterator(m_items, MaxValue, m_size); } @@ -292,12 +303,16 @@ class Vector: detail::VectorAllocator { constexpr const T &operator[](std::size_t i) const noexcept; + [[nodiscard]] Result front() noexcept; + [[nodiscard]] Result front() const noexcept; + [[nodiscard]] Result back() noexcept; + [[nodiscard]] Result back() const noexcept; [[nodiscard]] @@ -554,7 +569,7 @@ template constexpr void Vector::insert(std::size_t pos, const T &val) { // TODO: insert should ideally have its own expandCap if (m_size == m_cap) { - expandCap(m_cap ? m_cap * 2 : 100); + expandCap(m_cap ? m_cap * 2 : initialSize); } for (auto i = m_size; i > pos; --i) { new (&m_items[i]) T(std::move(m_items[i - 1])); @@ -567,7 +582,7 @@ template template constexpr T &Vector::emplace_back(Args&&... args) { if (m_size == m_cap) { - expandCap(m_cap ? m_cap * 2 : 100); + expandCap(m_cap ? m_cap * 2 : initialSize); } auto out = new (&m_items[m_size]) T{forward(args)...}; ++m_size; @@ -577,7 +592,7 @@ constexpr T &Vector::emplace_back(Args&&... args) { template constexpr void Vector::push_back(const T &item) { if (m_size == m_cap) { - expandCap(m_cap ? m_cap * 2 : 100); + expandCap(m_cap ? m_cap * 2 : initialSize); } new (&m_items[m_size]) T(item); ++m_size;