diff --git a/AK/ByteBuffer.h b/AK/ByteBuffer.h index 30785cab71e..76dc9c55c87 100644 --- a/AK/ByteBuffer.h +++ b/AK/ByteBuffer.h @@ -187,8 +187,6 @@ public: operator Bytes() { return bytes(); } operator ReadonlyBytes() const { return bytes(); } - ALWAYS_INLINE size_t capacity() const { return is_inline() ? inline_capacity : m_outline_capacity; } - private: ByteBuffer(size_t size) { @@ -238,6 +236,7 @@ private: } ALWAYS_INLINE bool is_inline() const { return m_size <= inline_capacity; } + ALWAYS_INLINE size_t capacity() const { return is_inline() ? inline_capacity : m_outline_capacity; } size_t m_size { 0 }; union { diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp index e834f3c9446..53a72f04dec 100644 --- a/AK/StringBuilder.cpp +++ b/AK/StringBuilder.cpp @@ -21,11 +21,10 @@ inline void StringBuilder::will_append(size_t size) Checked needed_capacity = m_length; needed_capacity += size; VERIFY(!needed_capacity.has_overflow()); - if (needed_capacity <= m_buffer.capacity()) - return; - Checked expanded_capacity = needed_capacity; - expanded_capacity *= 2; + // Prefer to completely use the inline buffer first + if (needed_capacity > inline_capacity) + expanded_capacity *= 2; VERIFY(!expanded_capacity.has_overflow()); m_buffer.grow(expanded_capacity.value()); }