mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-15 04:24:28 +00:00
common array: code chores.
remove duplicated logic this also changes the default grow size: N*2 -> N+(N/2)
This commit is contained in:
parent
c3af682f68
commit
5528eb9831
1 changed files with 1 additions and 7 deletions
|
@ -47,13 +47,7 @@ struct Array
|
||||||
void push(T element)
|
void push(T element)
|
||||||
{
|
{
|
||||||
if (count + 1 > reserved) {
|
if (count + 1 > reserved) {
|
||||||
reserved = (count + 1) * 2;
|
if (!reserve(count + (count >> 1) + 1)) return;
|
||||||
auto p = data;
|
|
||||||
data = static_cast<T*>(realloc(data, sizeof(T) * reserved));
|
|
||||||
if (!data) {
|
|
||||||
data = p;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
data[count++] = element;
|
data[count++] = element;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue