AK: Add an unsafe_shrink() method to Vector
This performs absolutely no checks, and does not *at all* modify the allocations in the vector, it also assumes that *some* elements exist for the vector to be shrunk.
This commit is contained in:
parent
12ca0cdd4a
commit
28d081abeb
1 changed files with 11 additions and 0 deletions
11
AK/Vector.h
11
AK/Vector.h
|
|
@ -947,6 +947,17 @@ public:
|
|||
update_metadata(); // We have *some* space, as new_size can't be zero here.
|
||||
}
|
||||
|
||||
void unsafe_shrink(size_t new_size)
|
||||
requires(want_fast_last_access)
|
||||
{
|
||||
if constexpr (!IsTriviallyDestructible<StorageType>) {
|
||||
for (size_t i = new_size; i < size(); ++i)
|
||||
at(i).~StorageType();
|
||||
}
|
||||
m_size = new_size;
|
||||
update_metadata(); // We have at least an allocation, as we are not freeing anything.
|
||||
}
|
||||
|
||||
void resize(size_t new_size, bool keep_capacity = false)
|
||||
requires(!contains_reference)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue