Skip to content

Commit 16ac549

Browse files
committed
Fix shrink_to_fit to swap buffer only when capacity is strictly smaller
1 parent f75126e commit 16ac549

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

libcxx/include/string

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3541,7 +3541,7 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocat
35413541
// The Standard mandates shrink_to_fit() does not increase the capacity.
35423542
// With equal capacity keep the existing buffer. This avoids extra work
35433543
// due to swapping the elements.
3544-
if (__allocation.count - 1 > capacity()) {
3544+
if (__allocation.count - 1 >= capacity()) {
35453545
__alloc_traits::deallocate(__alloc_, __allocation.ptr, __allocation.count);
35463546
return;
35473547
}

0 commit comments

Comments
 (0)