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:
Ali Mohammad Pur 2026-01-15 15:09:47 +01:00 committed by Ali Mohammad Pur
parent 12ca0cdd4a
commit 28d081abeb

View file

@ -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)
{