From 182cc57c2c538a03a1c91666d0e72f03d8f89a5a Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Thu, 6 Feb 2025 12:25:37 +0100 Subject: [PATCH] [libc++] Remove basic_string::__clear_and_shrink --- libcxx/include/string | 20 +++------ .../clear_and_shrink.pass.cpp | 44 ------------------- 2 files changed, 5 insertions(+), 59 deletions(-) delete mode 100644 libcxx/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink.pass.cpp diff --git a/libcxx/include/string b/libcxx/include/string index b7f2d12269463..11af160c0f8ff 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -1879,8 +1879,6 @@ public: _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const; - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __clear_and_shrink() _NOEXCEPT; - private: _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_STRING_INTERNAL_MEMORY_ACCESS bool __is_long() const _NOEXCEPT { @@ -2189,7 +2187,11 @@ private: __alloc_ = __str.__alloc_; else { if (!__str.__is_long()) { - __clear_and_shrink(); + if (__is_long()) { + __annotate_delete(); + __alloc_traits::deallocate(__alloc_, __get_long_pointer(), capacity() + 1); + __rep_ = __rep(); + } __alloc_ = __str.__alloc_; } else { __annotate_delete(); @@ -3820,18 +3822,6 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20 bool basic_string<_CharT, _Traits, _Allocat return true; } -// __clear_and_shrink - -template -inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT { - clear(); - if (__is_long()) { - __annotate_delete(); - __alloc_traits::deallocate(__alloc_, __get_long_pointer(), capacity() + 1); - __rep_ = __rep(); - } -} - // operator== template diff --git a/libcxx/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink.pass.cpp b/libcxx/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink.pass.cpp deleted file mode 100644 index 8f4c9102fde87..0000000000000 --- a/libcxx/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink.pass.cpp +++ /dev/null @@ -1,44 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// - -// Call __clear_and_shrink() and ensure string invariants hold - -#include -#include - -#include "test_macros.h" - -TEST_CONSTEXPR_CXX20 bool test() { - std::string l = "Long string so that allocation definitely, for sure, absolutely happens. Probably."; - std::string s = "short"; - - assert(l.__invariants()); - assert(s.__invariants()); - - s.__clear_and_shrink(); - assert(s.__invariants()); - assert(s.size() == 0); - - std::string::size_type cap = l.capacity(); - l.__clear_and_shrink(); - assert(l.__invariants()); - assert(l.size() == 0); - assert(l.capacity() < cap); - - return true; -} - -int main(int, char**) { - test(); -#if TEST_STD_VER > 17 - static_assert(test()); -#endif - return 0; -}