Skip to content

Commit ee3bcca

Browse files
authored
[libc++] Remove basic_string::__clear_and_shrink (llvm#126050)
`__clear_and_shrink` is only used in a single place and does more work than actually required.
1 parent 03478d6 commit ee3bcca

File tree

2 files changed

+5
-59
lines changed

2 files changed

+5
-59
lines changed

libcxx/include/string

+5-15
Original file line numberDiff line numberDiff line change
@@ -1879,8 +1879,6 @@ public:
18791879

18801880
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const;
18811881

1882-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __clear_and_shrink() _NOEXCEPT;
1883-
18841882
private:
18851883
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS bool
18861884
__is_long() const _NOEXCEPT {
@@ -2189,7 +2187,11 @@ private:
21892187
__alloc_ = __str.__alloc_;
21902188
else {
21912189
if (!__str.__is_long()) {
2192-
__clear_and_shrink();
2190+
if (__is_long()) {
2191+
__annotate_delete();
2192+
__alloc_traits::deallocate(__alloc_, __get_long_pointer(), capacity() + 1);
2193+
__rep_ = __rep();
2194+
}
21932195
__alloc_ = __str.__alloc_;
21942196
} else {
21952197
__annotate_delete();
@@ -3820,18 +3822,6 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20 bool basic_string<_CharT, _Traits, _Allocat
38203822
return true;
38213823
}
38223824

3823-
// __clear_and_shrink
3824-
3825-
template <class _CharT, class _Traits, class _Allocator>
3826-
inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT {
3827-
clear();
3828-
if (__is_long()) {
3829-
__annotate_delete();
3830-
__alloc_traits::deallocate(__alloc_, __get_long_pointer(), capacity() + 1);
3831-
__rep_ = __rep();
3832-
}
3833-
}
3834-
38353825
// operator==
38363826

38373827
template <class _CharT, class _Traits, class _Allocator>

libcxx/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink.pass.cpp

-44
This file was deleted.

0 commit comments

Comments
 (0)