summaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/libcxx/include/string
diff options
context:
space:
mode:
authorAndrey Khalyavin <[email protected]>2022-04-15 02:46:40 +0300
committerAndrey Khalyavin <[email protected]>2022-04-15 02:46:40 +0300
commitc5bfd90690e2df55f55d1831b0edd2e1c7241582 (patch)
treecda6bc446bf17fc110b67126b4c5ddc640fa427b /contrib/libs/cxxsupp/libcxx/include/string
parent599463a2ac4bda8536564ec6d7b798447755f05f (diff)
Update libc++ to b6d87773 (14 Jan 2022).
Notable changes: * implement operator << for filesystem::directory_entry * add std::ranges::in_in_result * add std::ranges::owning_view * add std::ranges::cdata * add std::ranges::construct_at and destroy{,_n,_at} * small fixes in std::ranges::data * SFINAE away std::ranges::cbegin(const T&&) for non-borrowed T * use arc4random to implement std::random_device on Apple * introduce __fits_in_sso to put constexpr check into a central place * introduce __debug_db_insert_c to put #if and constexpr check into a central place ref:b3dd06bd52f06e8939227ca0f0a5873d0c211e48
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/include/string')
-rw-r--r--contrib/libs/cxxsupp/libcxx/include/string135
1 files changed, 39 insertions, 96 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/include/string b/contrib/libs/cxxsupp/libcxx/include/string
index 4103c59a5df..95c7d1daece 100644
--- a/contrib/libs/cxxsupp/libcxx/include/string
+++ b/contrib/libs/cxxsupp/libcxx/include/string
@@ -846,10 +846,7 @@ public:
basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) {
_LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
__init(__s, traits_type::length(__s));
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _VSTD::__debug_db_insert_c(this);
}
template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
@@ -1501,6 +1498,11 @@ public:
#endif // _LIBCPP_DEBUG_LEVEL == 2
private:
+ _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI static bool __fits_in_sso(size_type __sz) {
+ // SSO is disabled during constant evaluation because `__is_long` isn't constexpr friendly
+ return !__libcpp_is_constant_evaluated() && (__sz < __min_cap);
+ }
+
_LIBCPP_INLINE_VISIBILITY
allocator_type& __alloc() _NOEXCEPT
{return __r_.second();}
@@ -1873,10 +1875,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
: __r_(__default_init_tag(), __default_init_tag())
{
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _VSTD::__debug_db_insert_c(this);
__zero();
}
@@ -1890,10 +1889,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __
#endif
: __r_(__default_init_tag(), __a)
{
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _VSTD::__debug_db_insert_c(this);
__zero();
}
@@ -1905,7 +1901,7 @@ void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
if (__reserve > max_size())
this->__throw_length_error();
pointer __p;
- if (__reserve < __min_cap)
+ if (__fits_in_sso(__reserve))
{
__set_short_size(__sz);
__p = __get_short_pointer();
@@ -1929,7 +1925,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_ty
if (__sz > max_size())
this->__throw_length_error();
pointer __p;
- if (__sz < __min_cap)
+ if (__fits_in_sso(__sz))
{
__set_short_size(__sz);
__p = __get_short_pointer();
@@ -1953,10 +1949,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const
{
_LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
__init(__s, traits_type::length(__s));
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _VSTD::__debug_db_insert_c(this);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -1964,12 +1957,9 @@ inline
basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
: __r_(__default_init_tag(), __default_init_tag())
{
- _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
- __init(__s, __n);
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
+ __init(__s, __n);
+ _VSTD::__debug_db_insert_c(this);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -1979,10 +1969,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
__init(__s, __n);
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _VSTD::__debug_db_insert_c(this);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -1994,11 +1981,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st
else
__init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
__str.__get_long_size());
-
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _VSTD::__debug_db_insert_c(this);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -2011,17 +1994,14 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(
else
__init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
__str.__get_long_size());
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _VSTD::__debug_db_insert_c(this);
}
template <class _CharT, class _Traits, class _Allocator>
void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
const value_type* __s, size_type __sz) {
pointer __p;
- if (__sz < __min_cap) {
+ if (__fits_in_sso(__sz)) {
__p = __get_short_pointer();
__set_short_size(__sz);
} else {
@@ -2049,12 +2029,10 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
: __r_(_VSTD::move(__str.__r_))
{
__str.__zero();
+ _VSTD::__debug_db_insert_c(this);
#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated()) {
- __get_db()->__insert_c(this);
- if (__is_long())
- __get_db()->swap(this, &__str);
- }
+ if (!__libcpp_is_constant_evaluated() && __is_long())
+ __get_db()->swap(this, &__str);
#endif
}
@@ -2070,12 +2048,10 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, co
__r_.first().__r = __str.__r_.first().__r;
__str.__zero();
}
+ _VSTD::__debug_db_insert_c(this);
#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated()) {
- __get_db()->__insert_c(this);
- if (__is_long())
- __get_db()->swap(this, &__str);
- }
+ if (!__libcpp_is_constant_evaluated() && __is_long())
+ __get_db()->swap(this, &__str);
#endif
}
@@ -2088,7 +2064,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
if (__n > max_size())
this->__throw_length_error();
pointer __p;
- if (__n < __min_cap)
+ if (__fits_in_sso(__n))
{
__set_short_size(__n);
__p = __get_short_pointer();
@@ -2111,10 +2087,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __
: __r_(__default_init_tag(), __default_init_tag())
{
__init(__n, __c);
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _VSTD::__debug_db_insert_c(this);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -2123,10 +2096,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __
: __r_(__default_init_tag(), __a)
{
__init(__n, __c);
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _VSTD::__debug_db_insert_c(this);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -2139,10 +2109,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st
if (__pos > __str_sz)
this->__throw_out_of_range();
__init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _VSTD::__debug_db_insert_c(this);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -2155,10 +2122,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st
if (__pos > __str_sz)
this->__throw_out_of_range();
__init(__str.data() + __pos, __str_sz - __pos);
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _VSTD::__debug_db_insert_c(this);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -2170,10 +2134,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(
__self_view __sv0 = __t;
__self_view __sv = __sv0.substr(__pos, __n);
__init(__sv.data(), __sv.size());
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _VSTD::__debug_db_insert_c(this);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -2183,10 +2144,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
{
__self_view __sv = __t;
__init(__sv.data(), __sv.size());
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _VSTD::__debug_db_insert_c(this);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -2196,10 +2154,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _
{
__self_view __sv = __t;
__init(__sv.data(), __sv.size());
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _VSTD::__debug_db_insert_c(this);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -2240,7 +2195,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _For
if (__sz > max_size())
this->__throw_length_error();
pointer __p;
- if (__sz < __min_cap)
+ if (__fits_in_sso(__sz))
{
__set_short_size(__sz);
__p = __get_short_pointer();
@@ -2279,10 +2234,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first,
: __r_(__default_init_tag(), __default_init_tag())
{
__init(__first, __last);
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _VSTD::__debug_db_insert_c(this);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -2293,10 +2245,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first,
: __r_(__default_init_tag(), __a)
{
__init(__first, __last);
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _VSTD::__debug_db_insert_c(this);
}
#ifndef _LIBCPP_CXX03_LANG
@@ -2308,10 +2257,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(
: __r_(__default_init_tag(), __default_init_tag())
{
__init(__il.begin(), __il.end());
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _VSTD::__debug_db_insert_c(this);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -2322,10 +2268,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(
: __r_(__default_init_tag(), __a)
{
__init(__il.begin(), __il.end());
-#if _LIBCPP_DEBUG_LEVEL == 2
- if (!__libcpp_is_constant_evaluated())
- __get_db()->__insert_c(this);
-#endif
+ _VSTD::__debug_db_insert_c(this);
}
#endif // _LIBCPP_CXX03_LANG
@@ -2444,7 +2387,7 @@ basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
- return (_LIBCPP_BUILTIN_CONSTANT_P(__n) && __n < __min_cap)
+ return (_LIBCPP_BUILTIN_CONSTANT_P(__n) && __fits_in_sso(__n))
? __assign_short(__s, __n)
: __assign_external(__s, __n);
}
@@ -2647,7 +2590,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
{
_LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
return _LIBCPP_BUILTIN_CONSTANT_P(*__s)
- ? (traits_type::length(__s) < __min_cap
+ ? (__fits_in_sso(traits_type::length(__s))
? __assign_short(__s, traits_type::length(__s))
: __assign_external(__s, traits_type::length(__s)))
: __assign_external(__s);