@@ -830,8 +830,8 @@ private:
830
830
{
831
831
union
832
832
{
833
- __long __l;
834
833
__short __s;
834
+ __long __l;
835
835
__raw __r;
836
836
};
837
837
};
@@ -879,19 +879,15 @@ public:
879
879
880
880
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string ()
881
881
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
882
- : __r_(__default_init_tag(), __default_init_tag()) {
883
- __default_init ();
884
- }
882
+ : __r_(__value_init_tag(), __default_init_tag()) {}
885
883
886
884
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string (const allocator_type& __a)
887
885
#if _LIBCPP_STD_VER <= 14
888
886
_NOEXCEPT_ (is_nothrow_copy_constructible<allocator_type>::value)
889
887
#else
890
888
_NOEXCEPT
891
889
#endif
892
- : __r_(__default_init_tag(), __a) {
893
- __default_init ();
894
- }
890
+ : __r_(__value_init_tag(), __a) {}
895
891
896
892
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string (const basic_string& __str)
897
893
: __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc())) {
@@ -917,7 +913,7 @@ public:
917
913
_NOEXCEPT
918
914
# endif
919
915
: __r_(std::move(__str.__r_)) {
920
- __str.__default_init ();
916
+ __str.__r_ . first () = __rep ();
921
917
}
922
918
923
919
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string (basic_string&& __str, const allocator_type& __a)
@@ -928,7 +924,7 @@ public:
928
924
if (__libcpp_is_constant_evaluated ())
929
925
__r_.first () = __rep ();
930
926
__r_.first () = __str.__r_ .first ();
931
- __str.__default_init ();
927
+ __str.__r_ . first () = __rep ();
932
928
}
933
929
}
934
930
#endif // _LIBCPP_CXX03_LANG
@@ -984,7 +980,7 @@ public:
984
980
auto __len = std::min<size_type>(__n, __str.size () - __pos);
985
981
if (__alloc_traits::is_always_equal::value || __alloc == __str.__alloc ()) {
986
982
__r_.first () = __str.__r_ .first ();
987
- __str.__default_init ();
983
+ __str.__r_ . first () = __rep ();
988
984
989
985
_Traits::move (data (), data () + __pos, __len);
990
986
__set_size (__len);
@@ -1729,8 +1725,9 @@ private:
1729
1725
1730
1726
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1731
1727
bool __is_long () const _NOEXCEPT {
1732
- if (__libcpp_is_constant_evaluated ())
1733
- return true ;
1728
+ if (__libcpp_is_constant_evaluated () && __builtin_constant_p (__r_.first ().__l .__is_long_ )) {
1729
+ return __r_.first ().__l .__is_long_ ;
1730
+ }
1734
1731
return __r_.first ().__s .__is_long_ ;
1735
1732
}
1736
1733
@@ -1746,26 +1743,8 @@ private:
1746
1743
#endif // _LIBCPP_STD_VER >= 20
1747
1744
}
1748
1745
1749
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __default_init () {
1750
- __r_.first () = __rep ();
1751
- if (__libcpp_is_constant_evaluated ()) {
1752
- size_type __sz = __recommend (0 ) + 1 ;
1753
- pointer __ptr = __alloc_traits::allocate (__alloc (), __sz);
1754
- __begin_lifetime (__ptr, __sz);
1755
- __set_long_pointer (__ptr);
1756
- __set_long_cap (__sz);
1757
- __set_long_size (0 );
1758
- }
1759
- }
1760
-
1761
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __deallocate_constexpr () {
1762
- if (__libcpp_is_constant_evaluated () && __get_pointer () != nullptr )
1763
- __alloc_traits::deallocate (__alloc (), __get_pointer (), __get_long_cap ());
1764
- }
1765
-
1766
1746
_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI static bool __fits_in_sso (size_type __sz) {
1767
- // SSO is disabled during constant evaluation because `__is_long` isn't constexpr friendly
1768
- return !__libcpp_is_constant_evaluated () && (__sz < __min_cap);
1747
+ return __sz < __min_cap;
1769
1748
}
1770
1749
1771
1750
template <class _Iterator , class _Sentinel >
@@ -1877,10 +1856,7 @@ private:
1877
1856
size_type __recommend (size_type __s) _NOEXCEPT
1878
1857
{
1879
1858
if (__s < __min_cap) {
1880
- if (__libcpp_is_constant_evaluated ())
1881
- return static_cast <size_type>(__min_cap);
1882
- else
1883
- return static_cast <size_type>(__min_cap) - 1 ;
1859
+ return static_cast <size_type>(__min_cap) - 1 ;
1884
1860
}
1885
1861
size_type __guess = __align_it<sizeof (value_type) < __alignment ?
1886
1862
__alignment/sizeof (value_type) : 1 > (__s+1 ) - 1 ;
@@ -2021,7 +1997,7 @@ private:
2021
1997
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_external (const value_type* __s, size_type __n);
2022
1998
2023
1999
// Assigns the value in __s, guaranteed to be __n < __min_cap in length.
2024
- inline basic_string& __assign_short (const value_type* __s, size_type __n) {
2000
+ inline _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_short (const value_type* __s, size_type __n) {
2025
2001
pointer __p = __is_long ()
2026
2002
? (__set_long_size (__n), __get_long_pointer ())
2027
2003
: (__set_short_size (__n), __get_short_pointer ());
@@ -2235,7 +2211,7 @@ template <class _CharT, class _Traits, class _Allocator>
2235
2211
template <class _InputIterator , class _Sentinel >
2236
2212
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
2237
2213
void basic_string<_CharT, _Traits, _Allocator>::__init_with_sentinel(_InputIterator __first, _Sentinel __last) {
2238
- __default_init ();
2214
+ __r_. first () = __rep ();
2239
2215
2240
2216
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2241
2217
try
@@ -2335,7 +2311,7 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2335
2311
if (__sec_cp_sz != 0 )
2336
2312
traits_type::copy (std::__to_address (__p) + __n_copy + __n_add,
2337
2313
std::__to_address (__old_p) + __n_copy + __n_del, __sec_cp_sz);
2338
- if (__old_cap+1 != __min_cap || __libcpp_is_constant_evaluated () )
2314
+ if (__old_cap+1 != __min_cap)
2339
2315
__alloc_traits::deallocate (__alloc (), __old_p, __old_cap+1 );
2340
2316
__set_long_pointer (__p);
2341
2317
__set_long_cap (__allocation.count );
@@ -2375,7 +2351,7 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_t
2375
2351
traits_type::copy (std::__to_address (__p) + __n_copy + __n_add,
2376
2352
std::__to_address (__old_p) + __n_copy + __n_del,
2377
2353
__sec_cp_sz);
2378
- if (__libcpp_is_constant_evaluated () || __old_cap + 1 != __min_cap)
2354
+ if (__old_cap + 1 != __min_cap)
2379
2355
__alloc_traits::deallocate (__alloc (), __old_p, __old_cap + 1 );
2380
2356
__set_long_pointer (__p);
2381
2357
__set_long_cap (__allocation.count );
@@ -2538,12 +2514,8 @@ basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, tr
2538
2514
}
2539
2515
__move_assign_alloc (__str);
2540
2516
__r_.first () = __str.__r_ .first ();
2541
- if (__libcpp_is_constant_evaluated ()) {
2542
- __str.__default_init ();
2543
- } else {
2544
- __str.__set_short_size (0 );
2545
- traits_type::assign (__str.__get_short_pointer ()[0 ], value_type ());
2546
- }
2517
+ __str.__set_short_size (0 );
2518
+ traits_type::assign (__str.__get_short_pointer ()[0 ], value_type ());
2547
2519
}
2548
2520
2549
2521
#endif
@@ -2829,13 +2801,6 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_t
2829
2801
if (__pos > __sz)
2830
2802
__throw_out_of_range ();
2831
2803
size_type __cap = capacity ();
2832
- if (__libcpp_is_constant_evaluated ()) {
2833
- if (__cap - __sz >= __n)
2834
- __grow_by_and_replace (__cap, 0 , __sz, __pos, 0 , __n, __s);
2835
- else
2836
- __grow_by_and_replace (__cap, __sz + __n - __cap, __sz, __pos, 0 , __n, __s);
2837
- return *this ;
2838
- }
2839
2804
if (__cap - __sz >= __n)
2840
2805
{
2841
2806
if (__n)
@@ -2844,7 +2809,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_t
2844
2809
size_type __n_move = __sz - __pos;
2845
2810
if (__n_move != 0 )
2846
2811
{
2847
- if (__p + __pos <= __s && __s < __p + __sz)
2812
+ if (std::__is_pointer_in_range ( __p + __pos, __p + __sz, __s) )
2848
2813
__s += __n;
2849
2814
traits_type::move (__p + __pos + __n, __p + __pos, __n_move);
2850
2815
}
@@ -3867,7 +3832,7 @@ basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
3867
3832
if (__is_long ())
3868
3833
{
3869
3834
__alloc_traits::deallocate (__alloc (), __get_long_pointer (), capacity () + 1 );
3870
- __default_init ();
3835
+ __r_. first () = __rep ();
3871
3836
}
3872
3837
}
3873
3838
0 commit comments