summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-05-17 23:18:34 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-18 08:06:32 +0200
commit3908a49661a00e15621748dcb2b0424f29433571 (patch)
tree771906bc5efc58b0dc5fac497c74e43ee40326d6
parentf91bcb8895cd6b76b2977ad0632fef521ba2f1d1 (diff)
downloadserenity-3908a49661a00e15621748dcb2b0424f29433571.zip
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.
-rw-r--r--AK/StringBuilder.cpp5
1 files changed, 4 insertions, 1 deletions
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<size_t> needed_capacity = m_length;
needed_capacity += size;
VERIFY(!needed_capacity.has_overflow());
- m_buffer.grow(needed_capacity.value());
+ Checked<size_t> expanded_capacity = needed_capacity;
+ expanded_capacity *= 2;
+ VERIFY(!expanded_capacity.has_overflow());
+ m_buffer.grow(expanded_capacity.value());
}
StringBuilder::StringBuilder(size_t initial_capacity)