[libcxx-commits] [libcxx] [libc++] Introduce basic_string::__allocate_long_buffer_for_growing (PR #162633)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Nov 19 08:07:04 PST 2025
================
@@ -2285,6 +2285,22 @@ private:
return __long(__buffer, __capacity);
}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __long
+ __allocate_long_buffer_for_growing(_Allocator& __alloc, size_type __required_capacity) {
----------------
ldionne wrote:
I'd like to capture the fact that this growth pattern is intended specifically to prevent quadratic behavior when pushing back N elements into the string. As it stands, I find the name somewhat confusing since we almost always call `__allocate_long_buffer` for growing in some way, already.
If we have that, then I think that whether we perform the allocation in this function or outside it is not super important.
We should also add a comment explaining that it's the purpose of that function.
Maybe `__allocate_long_buffer_for_amortized_growth`? Or, at that point, just `__get_amortized_growth_capacity` and then allocate in the existing `__allocate_long_buffer`?
https://github.com/llvm/llvm-project/pull/162633
More information about the libcxx-commits
mailing list