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

View file

@ -215,17 +215,21 @@ private:
void trim(size_t size, bool may_discard_existing_data)
{
VERIFY(size <= m_size);
if (!m_inline && size <= inline_capacity) {
// 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)
__builtin_memcpy(m_inline_buffer, outline_buffer, size);
kfree(outline_buffer);
m_inline = true;
}
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)
__builtin_memcpy(m_inline_buffer, outline_buffer, size);
kfree(outline_buffer);
m_inline = true;
}
NEVER_INLINE void ensure_capacity_slowpath(size_t new_capacity)
{
u8* new_buffer;