[libcxx-commits] [libcxx] [libc++] Refactor basic_string::__recommend (PR #162631)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Mon Oct 27 10:15:15 PDT 2025


================
@@ -2347,16 +2349,17 @@ private:
     return (__s + (__a - 1)) & ~(__a - 1);
   }
   enum { __alignment = 8 };
-  static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type __recommend(size_type __s) _NOEXCEPT {
-    if (__s < __min_cap) {
-      return static_cast<size_type>(__min_cap) - 1;
-    }
+
+  _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
+  __align_allocation_size(size_type __size) _NOEXCEPT {
+    _LIBCPP_ASSERT_INTERNAL(
+        !__fits_in_sso(__size), "Trying to align allocation of a size which would fit into the SSO");
     const size_type __boundary = sizeof(value_type) < __alignment ? __alignment / sizeof(value_type) : __endian_factor;
-    size_type __guess          = __align_it<__boundary>(__s + 1) - 1;
-    if (__guess == __min_cap)
+    size_type __guess          = __align_it<__boundary>(__size + 1);
----------------
philnik777 wrote:

I've changed it to return the allocation size including the null terminator. This way to call sites don't have to add one anymore.

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


More information about the libcxx-commits mailing list