diff --git a/AK/ByteBuffer.h b/AK/ByteBuffer.h index 3d130940f4..6bdfe300f6 100644 --- a/AK/ByteBuffer.h +++ b/AK/ByteBuffer.h @@ -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;