libluna: Make Vector grow exponentially

This commit is contained in:
apio 2023-08-22 11:53:42 +02:00
parent 30ff704342
commit 70a232cfcd
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -62,7 +62,7 @@ template <typename T> class Vector
Result<void> try_append(T&& item)
{
if (m_capacity == m_size) TRY(resize(m_capacity + 8));
if (m_capacity == m_size) TRY(resize(m_capacity ? m_capacity * 2 : 8));
new (&m_data[m_size]) T(move(item));
@ -252,6 +252,8 @@ template <typename T> class Vector
Result<void> resize(usize new_capacity)
{
if (new_capacity < m_capacity) return {};
const usize new_byte_capacity = new_capacity * sizeof(T);
void* const ptr = TRY(realloc_impl(m_data, new_byte_capacity));