[libcxx-commits] [libcxx] [libc++] Refactor how we do amortized growth (PR #171117)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jan 21 07:49:07 PST 2026
================
@@ -2285,6 +2285,25 @@ private:
return __long(__buffer, __capacity);
}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __long
+ __allocate_long_buffer_for_amortized_growth(size_type __required_size) {
----------------
ldionne wrote:
Instead, we could take the required size as an additional parameter of `__allocate_long_buffer`. That would address cases like in `reserve` where we need the same functionality without growing for amortized growth.
```
__long __buffer = __allocate_long_buffer(__alloc_, /* used size */ __requested_capacity,
/* min capacity */ __requested_capacity);
```
This also has the benefit of documenting that we're growing to exactly what we need, no more.
The major benefit I see here is to keep allocation and the determination of the capacity we need separate, which I think is really neat in the current API.
https://github.com/llvm/llvm-project/pull/171117
More information about the libcxx-commits
mailing list