mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:57:44 +00:00
AK: Delete Vector::resize() from Nonnull{Own,Ref}PtrVector.
It's not possible to grow one of these vectors beyond what's already in them since it's not possible to default-construct Nonnull{Own,Ref}Ptr. Add Vector::shrink() which can be used when you want to shrink the Vector and delete resize() from the specialized Vectors.
This commit is contained in:
parent
394168c0ca
commit
1686c4906b
3 changed files with 27 additions and 9 deletions
24
AK/Vector.h
24
AK/Vector.h
|
@ -407,8 +407,9 @@ public:
|
|||
m_capacity = new_capacity;
|
||||
}
|
||||
|
||||
void resize(int new_size)
|
||||
void shrink(int new_size)
|
||||
{
|
||||
ASSERT(new_size <= size());
|
||||
if (new_size == size())
|
||||
return;
|
||||
|
||||
|
@ -417,14 +418,19 @@ public:
|
|||
return;
|
||||
}
|
||||
|
||||
if (new_size > size()) {
|
||||
ensure_capacity(new_size);
|
||||
for (int i = size(); i < new_size; ++i)
|
||||
new (slot(i)) T;
|
||||
} else {
|
||||
for (int i = new_size; i < size(); ++i)
|
||||
at(i).~T();
|
||||
}
|
||||
for (int i = new_size; i < size(); ++i)
|
||||
at(i).~T();
|
||||
m_size = new_size;
|
||||
}
|
||||
|
||||
void resize(int new_size)
|
||||
{
|
||||
if (new_size <= size())
|
||||
return shrink(new_size);
|
||||
|
||||
ensure_capacity(new_size);
|
||||
for (int i = size(); i < new_size; ++i)
|
||||
new (slot(i)) T;
|
||||
m_size = new_size;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue