common array: code chores.

remove duplicated logic
this also changes the default grow size: N*2 -> N+(N/2)
This commit is contained in:
Hermet Park 2023-07-13 12:58:16 +09:00 committed by Hermet Park
parent c3af682f68
commit 5528eb9831

View file

@ -47,13 +47,7 @@ struct Array
void push(T element)
{
if (count + 1 > reserved) {
reserved = (count + 1) * 2;
auto p = data;
data = static_cast<T*>(realloc(data, sizeof(T) * reserved));
if (!data) {
data = p;
return;
}
if (!reserve(count + (count >> 1) + 1)) return;
}
data[count++] = element;
}