[libcxx-commits] [libcxx] Change 'grow_by' to use precise size for the first SSO --> long allocation (PR #69967)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Oct 25 09:30:38 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();
----------------
EricWF wrote:

I'm trying to keep the messy case for `__cap` as the second operand, so I'll just negate the variable names and go from there.

https://github.com/llvm/llvm-project/pull/69967


More information about the libcxx-commits mailing list