From 425bfabd6615f19707e7cd935a8ccaa1772617d8 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 31 May 2021 01:17:24 +0200 Subject: [PATCH] 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. --- AK/ByteBuffer.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) 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;