AK: Split the ByteBuffer::trim method into two methods

This allows us to mark the slow part (i.e. where we copy the buffer) as
NEVER_INLINE because this should almost never get called and therefore
should also not get inlined into callers.
This commit is contained in:
Gunnar Beutner 2021-05-31 01:17:24 +02:00 committed by Ali Mohammad Pur
parent d8b5fa9dfe
commit 425bfabd66
Notes: sideshowbarker 2024-07-18 17:08:15 +09:00

View file

@ -215,7 +215,13 @@ private:
void trim(size_t size, bool may_discard_existing_data)
{
VERIFY(size <= m_size);
if (!m_inline && size <= inline_capacity) {
if (!m_inline && size <= inline_capacity)
shrink_into_inline_buffer(size, may_discard_existing_data);
m_size = size;
}
NEVER_INLINE void shrink_into_inline_buffer(size_t size, bool may_discard_existing_data)
{
// m_inline_buffer and m_outline_buffer are part of a union, so save the pointer
auto outline_buffer = m_outline_buffer;
if (!may_discard_existing_data)
@ -223,8 +229,6 @@ private:
kfree(outline_buffer);
m_inline = true;
}
m_size = size;
}
NEVER_INLINE void ensure_capacity_slowpath(size_t new_capacity)
{