[ox/std] Change initial Vector size to small vector size
This commit is contained in:
parent
bb0592ade8
commit
0e4bebcc3d
21
deps/ox/src/ox/std/vector.hpp
vendored
21
deps/ox/src/ox/std/vector.hpp
vendored
@ -217,6 +217,7 @@ class Vector: detail::VectorAllocator<T, SmallVectorSize> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static constexpr auto initialSize = SmallVectorSize > 0 ? SmallVectorSize : 50;
|
||||||
std::size_t m_size = 0;
|
std::size_t m_size = 0;
|
||||||
std::size_t m_cap = 0;
|
std::size_t m_cap = 0;
|
||||||
T *m_items = nullptr;
|
T *m_items = nullptr;
|
||||||
@ -242,42 +243,52 @@ class Vector: detail::VectorAllocator<T, SmallVectorSize> {
|
|||||||
return iterator<>(m_items, m_size, m_size);
|
return iterator<>(m_items, m_size, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr iterator<const T&, const T*> begin() const noexcept {
|
constexpr iterator<const T&, const T*> begin() const noexcept {
|
||||||
return iterator<const T&, const T*>(m_items, 0, m_size);
|
return iterator<const T&, const T*>(m_items, 0, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr iterator<const T&, const T*> end() const noexcept {
|
constexpr iterator<const T&, const T*> end() const noexcept {
|
||||||
return iterator<const T&, const T*>(m_items, m_size, m_size);
|
return iterator<const T&, const T*>(m_items, m_size, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr iterator<const T&, const T*> cbegin() const noexcept {
|
constexpr iterator<const T&, const T*> cbegin() const noexcept {
|
||||||
return iterator<const T&, const T*>(m_items, 0, m_size);
|
return iterator<const T&, const T*>(m_items, 0, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr iterator<const T&, const T*> cend() const noexcept {
|
constexpr iterator<const T&, const T*> cend() const noexcept {
|
||||||
return iterator<const T&, const T*>(m_items, m_size, m_size);
|
return iterator<const T&, const T*>(m_items, m_size, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr iterator<T&, T*, true> rbegin() noexcept {
|
constexpr iterator<T&, T*, true> rbegin() noexcept {
|
||||||
return iterator<T&, T*, true>(m_items, m_size - 1, m_size);
|
return iterator<T&, T*, true>(m_items, m_size - 1, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr iterator<T&, T*, true> rend() noexcept {
|
constexpr iterator<T&, T*, true> rend() noexcept {
|
||||||
return iterator<T&, T*, true>(m_items, MaxValue<size_type>, m_size);
|
return iterator<T&, T*, true>(m_items, MaxValue<size_type>, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr iterator<const T&, const T*, true> crbegin() const noexcept {
|
constexpr iterator<const T&, const T*, true> crbegin() const noexcept {
|
||||||
return iterator<const T&, const T*, true>(m_items, m_size - 1, m_size);
|
return iterator<const T&, const T*, true>(m_items, m_size - 1, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr iterator<const T&, const T*, true> crend() const noexcept {
|
constexpr iterator<const T&, const T*, true> crend() const noexcept {
|
||||||
return iterator<const T&, const T*, true>(m_items, MaxValue<size_type>, m_size);
|
return iterator<const T&, const T*, true>(m_items, MaxValue<size_type>, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr iterator<const T&, const T*, true> rbegin() const noexcept {
|
constexpr iterator<const T&, const T*, true> rbegin() const noexcept {
|
||||||
return iterator<const T&, const T*, true>(m_items, m_size - 1, m_size);
|
return iterator<const T&, const T*, true>(m_items, m_size - 1, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr iterator<const T&, const T*, true> rend() const noexcept {
|
constexpr iterator<const T&, const T*, true> rend() const noexcept {
|
||||||
return iterator<const T&, const T*, true>(m_items, MaxValue<size_type>, m_size);
|
return iterator<const T&, const T*, true>(m_items, MaxValue<size_type>, m_size);
|
||||||
}
|
}
|
||||||
@ -292,12 +303,16 @@ class Vector: detail::VectorAllocator<T, SmallVectorSize> {
|
|||||||
|
|
||||||
constexpr const T &operator[](std::size_t i) const noexcept;
|
constexpr const T &operator[](std::size_t i) const noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
Result<T&> front() noexcept;
|
Result<T&> front() noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
Result<const T&> front() const noexcept;
|
Result<const T&> front() const noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
Result<T&> back() noexcept;
|
Result<T&> back() noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
Result<const T&> back() const noexcept;
|
Result<const T&> back() const noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
@ -554,7 +569,7 @@ template<typename T, std::size_t SmallVectorSize>
|
|||||||
constexpr void Vector<T, SmallVectorSize>::insert(std::size_t pos, const T &val) {
|
constexpr void Vector<T, SmallVectorSize>::insert(std::size_t pos, const T &val) {
|
||||||
// TODO: insert should ideally have its own expandCap
|
// TODO: insert should ideally have its own expandCap
|
||||||
if (m_size == m_cap) {
|
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) {
|
for (auto i = m_size; i > pos; --i) {
|
||||||
new (&m_items[i]) T(std::move(m_items[i - 1]));
|
new (&m_items[i]) T(std::move(m_items[i - 1]));
|
||||||
@ -567,7 +582,7 @@ template<typename T, std::size_t SmallVectorSize>
|
|||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
constexpr T &Vector<T, SmallVectorSize>::emplace_back(Args&&... args) {
|
constexpr T &Vector<T, SmallVectorSize>::emplace_back(Args&&... args) {
|
||||||
if (m_size == m_cap) {
|
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>(args)...};
|
auto out = new (&m_items[m_size]) T{forward<Args>(args)...};
|
||||||
++m_size;
|
++m_size;
|
||||||
@ -577,7 +592,7 @@ constexpr T &Vector<T, SmallVectorSize>::emplace_back(Args&&... args) {
|
|||||||
template<typename T, std::size_t SmallVectorSize>
|
template<typename T, std::size_t SmallVectorSize>
|
||||||
constexpr void Vector<T, SmallVectorSize>::push_back(const T &item) {
|
constexpr void Vector<T, SmallVectorSize>::push_back(const T &item) {
|
||||||
if (m_size == m_cap) {
|
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);
|
new (&m_items[m_size]) T(item);
|
||||||
++m_size;
|
++m_size;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user