From 3908a49661a00e15621748dcb2b0424f29433571 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 17 May 2021 23:18:34 +0200 Subject: [PATCH] AK: Revert removal of StringBuilder::will_append optimization This was removed as part of the ByteBuffer changes but the allocation optimization is still necessary at least for non-SerenityOS targets where malloc_good_size() isn't supported or returns a small value and causes a whole bunch of unnecessary reallocations. --- AK/StringBuilder.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp index 68d5343578..b05488e00d 100644 --- a/AK/StringBuilder.cpp +++ b/AK/StringBuilder.cpp @@ -21,7 +21,10 @@ inline void StringBuilder::will_append(size_t size) Checked needed_capacity = m_length; needed_capacity += size; VERIFY(!needed_capacity.has_overflow()); - m_buffer.grow(needed_capacity.value()); + Checked expanded_capacity = needed_capacity; + expanded_capacity *= 2; + VERIFY(!expanded_capacity.has_overflow()); + m_buffer.grow(expanded_capacity.value()); } StringBuilder::StringBuilder(size_t initial_capacity)