Skip to content

Commit 3c58f67

Browse files
refactor
1 parent fd54b6a commit 3c58f67

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

libcxx/include/string

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,13 +1206,7 @@ public:
12061206
}
12071207
# endif // _LIBCPP_CXX03_LANG
12081208

1209-
inline _LIBCPP_CONSTEXPR_SINCE_CXX20 ~basic_string() {
1210-
// We do not use __reset_internal_buffer() here to avoid the overhead of
1211-
// resetting the object.
1212-
__annotate_delete();
1213-
if (__is_long())
1214-
__alloc_traits::deallocate(__alloc_, __get_long_pointer(), __get_long_cap());
1215-
}
1209+
inline _LIBCPP_CONSTEXPR_SINCE_CXX20 ~basic_string() { __deallocate_buffer_if_long(); }
12161210

12171211
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 operator __self_view() const _NOEXCEPT {
12181212
return __self_view(typename __self_view::__assume_valid(), data(), size());
@@ -2265,11 +2259,15 @@ private:
22652259
return __long(__buffer, __capacity);
22662260
}
22672261

2268-
// Deallocate the long buffer if it exists and clear the short buffer so we are an empty string
2269-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __reset_internal_buffer() {
2262+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __deallocate_buffer_if_long() {
22702263
__annotate_delete();
22712264
if (__is_long())
22722265
__alloc_traits::deallocate(__alloc_, __get_long_pointer(), __get_long_cap());
2266+
}
2267+
2268+
// Deallocate the long buffer if it exists and clear the short buffer so we are an empty string
2269+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __reset_internal_buffer() {
2270+
__deallocate_buffer_if_long();
22732271
__rep_.__s = __short();
22742272
}
22752273

0 commit comments

Comments
 (0)