diff --git a/libcxx/include/string b/libcxx/include/string index 98297d04d0c61..706b80aab4c8f 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -2292,14 +2292,9 @@ private: } 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(__min_cap) - 1; - } + _LIBCPP_ASSERT_INTERNAL(__s >= __min_cap, "recommend is called for small string capacity"); 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) - __guess += __endian_factor; - _LIBCPP_ASSERT_INTERNAL(__guess >= __s, "recommendation is below the requested size"); return __guess; } @@ -3435,7 +3430,9 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::re template inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT { - size_type __target_capacity = __recommend(size()); + size_type __target_capacity = size(); + __target_capacity = + __target_capacity < __min_cap ? static_cast(__min_cap) - 1 : __recommend(__target_capacity); if (__target_capacity == capacity()) return;