Skip to content

Fix capacity increase issue with shrink_to_fit for __split_buffer #117720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions libcxx/include/__split_buffer
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,14 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void __split_buffer<_Tp, _Allocator>::shrink_to_fi
try {
#endif // _LIBCPP_HAS_EXCEPTIONS
__split_buffer<value_type, __alloc_rr&> __t(size(), 0, __alloc_);
__t.__construct_at_end(move_iterator<pointer>(__begin_), move_iterator<pointer>(__end_));
__t.__end_ = __t.__begin_ + (__end_ - __begin_);
std::swap(__first_, __t.__first_);
std::swap(__begin_, __t.__begin_);
std::swap(__end_, __t.__end_);
std::swap(__cap_, __t.__cap_);
if (__t.capacity() < capacity()) {
__t.__construct_at_end(move_iterator<pointer>(__begin_), move_iterator<pointer>(__end_));
__t.__end_ = __t.__begin_ + (__end_ - __begin_);
std::swap(__first_, __t.__first_);
std::swap(__begin_, __t.__begin_);
std::swap(__end_, __t.__end_);
std::swap(__cap_, __t.__cap_);
}
#if _LIBCPP_HAS_EXCEPTIONS
} catch (...) {
}
Expand Down
Loading