AK: Replace ByteBuffer::grow with resize()/ensure_capacity()

Previously ByteBuffer::grow() behaved like Vector<T>::resize().
However the function name was somewhat ambiguous - and so this patch
updates ByteBuffer to behave more like Vector<T> by replacing grow()
with resize() and adding an ensure_capacity() method.

This also lets the user change the buffer's capacity without affecting
the size which was not previously possible.

Additionally this patch makes the capacity() method public (again).
This commit is contained in:
Gunnar Beutner 2021-05-31 00:31:46 +02:00 committed by Ali Mohammad Pur
commit 5f18cf75c5
Notes: sideshowbarker 2024-07-18 17:08:23 +09:00
7 changed files with 41 additions and 32 deletions

View file

@ -332,7 +332,7 @@ public:
if (m_type.limits().max().value_or(new_size) < new_size)
return false;
auto previous_size = m_size;
m_data.grow(new_size);
m_data.resize(new_size);
m_size = new_size;
// The spec requires that we zero out everything on grow
__builtin_memset(m_data.offset_pointer(previous_size), 0, size_to_grow);