mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
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:
parent
d8b5fa9dfe
commit
425bfabd66
Notes:
sideshowbarker
2024-07-18 17:08:15 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/425bfabd661 Pull-request: https://github.com/SerenityOS/serenity/pull/7609 Reviewed-by: https://github.com/alimpfard
1 changed files with 12 additions and 8 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue