[libcxx-commits] [libcxx] [libc++] Refactor basic_string::__recommend (PR #162631)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Oct 10 10:02:44 PDT 2025
================
@@ -3410,18 +3411,15 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::re
template <class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT {
- size_type __target_capacity = __recommend(size());
- if (__target_capacity == capacity())
+ if (!__is_long())
return;
- _LIBCPP_ASSERT_INTERNAL(__is_long(), "Trying to shrink small string");
-
// We're a long string and we're shrinking into the small buffer.
const auto __ptr = __get_long_pointer();
const auto __size = __get_long_size();
const auto __cap = __get_long_cap();
- if (__fits_in_sso(__target_capacity)) {
+ if (__fits_in_sso(__align_allocation_size(size()))) {
----------------
ldionne wrote:
That looks wrong to me. Do you mean to be discarding the result of `__align_allocation_size`?
https://github.com/llvm/llvm-project/pull/162631
More information about the libcxx-commits
mailing list