[ox/std] Change initial Vector size to small vector size

This commit is contained in:
Gary Talent 2022-02-16 02:28:00 -06:00
parent bb0592ade8
commit 0e4bebcc3d

View File

@ -217,6 +217,7 @@ class Vector: detail::VectorAllocator<T, SmallVectorSize> {
};
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<T, SmallVectorSize> {
return iterator<>(m_items, m_size, m_size);
}
[[nodiscard]]
constexpr iterator<const T&, const T*> begin() const noexcept {
return iterator<const T&, const T*>(m_items, 0, m_size);
}
[[nodiscard]]
constexpr iterator<const T&, const T*> end() const noexcept {
return iterator<const T&, const T*>(m_items, m_size, m_size);
}
[[nodiscard]]
constexpr iterator<const T&, const T*> cbegin() const noexcept {
return iterator<const T&, const T*>(m_items, 0, m_size);
}
[[nodiscard]]
constexpr iterator<const T&, const T*> cend() const noexcept {
return iterator<const T&, const T*>(m_items, m_size, m_size);
}
[[nodiscard]]
constexpr iterator<T&, T*, true> rbegin() noexcept {
return iterator<T&, T*, true>(m_items, m_size - 1, m_size);
}
[[nodiscard]]
constexpr iterator<T&, T*, true> rend() noexcept {
return iterator<T&, T*, true>(m_items, MaxValue<size_type>, m_size);
}
[[nodiscard]]
constexpr iterator<const T&, const T*, true> crbegin() const noexcept {
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 {
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 {
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 {
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;
[[nodiscard]]
Result<T&> front() noexcept;
[[nodiscard]]
Result<const T&> front() const noexcept;
[[nodiscard]]
Result<T&> back() noexcept;
[[nodiscard]]
Result<const T&> back() const noexcept;
[[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) {
// 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<typename T, std::size_t SmallVectorSize>
template<typename... Args>
constexpr T &Vector<T, SmallVectorSize>::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>(args)...};
++m_size;
@ -577,7 +592,7 @@ constexpr T &Vector<T, SmallVectorSize>::emplace_back(Args&&... args) {
template<typename T, std::size_t SmallVectorSize>
constexpr void Vector<T, SmallVectorSize>::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;