mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 21:54:40 +03:00
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.
This commit is contained in:
parent
f91bcb8895
commit
3908a49661
Notes:
sideshowbarker
2024-07-18 17:53:41 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/3908a49661a Pull-request: https://github.com/SerenityOS/serenity/pull/7225
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user