[libcxx-commits] [libcxx] Change 'grow_by' to use precise size for the first SSO --> long allocation (PR #69967)
Martijn Vels via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Oct 24 10:24:04 PDT 2023
================
@@ -2311,10 +2311,13 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
size_type __ms = max_size();
if (__delta_cap > __ms - __old_cap - 1)
__throw_length_error();
- pointer __old_p = __get_pointer();
- size_type __cap = __old_cap < __ms / 2 - __alignment ?
- __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) :
- __ms - 1;
+ const bool __was_long = __is_long();
+ pointer __old_p = !__was_long ? __get_short_pointer() : __get_long_pointer();
----------------
martijnvels wrote:
Can we remove the negation, i.e.:
`__was_long ? __get_long_pointer() : __get_short_pointer();`
Which reduces my cognitive load by one point :) Here and below.
https://github.com/llvm/llvm-project/pull/69967
More information about the libcxx-commits
mailing list