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

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Nov 8 16:39:10 PST 2023


================
@@ -2315,10 +2315,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_short = !__is_long();
+    pointer __old_p        = __was_short ? __get_short_pointer() : __get_long_pointer();
----------------
ldionne wrote:

Any reason why we're not still using `__get_pointer()` here? Is it just because we've already computed `__was_short`?

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


More information about the libcxx-commits mailing list