libluna: Make Vector grow exponentially
This commit is contained in:
parent
30ff704342
commit
70a232cfcd
@ -62,7 +62,7 @@ template <typename T> class Vector
|
|||||||
|
|
||||||
Result<void> try_append(T&& item)
|
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));
|
new (&m_data[m_size]) T(move(item));
|
||||||
|
|
||||||
@ -252,6 +252,8 @@ template <typename T> class Vector
|
|||||||
|
|
||||||
Result<void> resize(usize new_capacity)
|
Result<void> resize(usize new_capacity)
|
||||||
{
|
{
|
||||||
|
if (new_capacity < m_capacity) return {};
|
||||||
|
|
||||||
const usize new_byte_capacity = new_capacity * sizeof(T);
|
const usize new_byte_capacity = new_capacity * sizeof(T);
|
||||||
|
|
||||||
void* const ptr = TRY(realloc_impl(m_data, new_byte_capacity));
|
void* const ptr = TRY(realloc_impl(m_data, new_byte_capacity));
|
||||||
|
Loading…
Reference in New Issue
Block a user