@@ -2246,6 +2246,10 @@ private:
2246
2246
friend constexpr basic_string operator + <>(const basic_string&, type_identity_t <__self_view>);
2247
2247
friend constexpr basic_string operator + <>(type_identity_t <__self_view>, const basic_string&);
2248
2248
#endif
2249
+
2250
+ template <class _CharT2 , class _Traits2 , class _Allocator2 >
2251
+ friend inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool
2252
+ operator ==(const basic_string<_CharT2, _Traits2, _Allocator2>&, const _CharT2*) _NOEXCEPT;
2249
2253
};
2250
2254
2251
2255
// These declarations must appear before any functions are implicitly used
@@ -3855,16 +3859,18 @@ operator==(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>&
3855
3859
template <class _CharT , class _Traits , class _Allocator >
3856
3860
inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool
3857
3861
operator ==(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) _NOEXCEPT {
3858
- #if _LIBCPP_STD_VER >= 20
3859
- return basic_string_view<_CharT, _Traits>(__lhs) == basic_string_view<_CharT, _Traits>(__rhs);
3860
- #else
3861
- typedef basic_string<_CharT, _Traits, _Allocator> _String;
3862
3862
_LIBCPP_ASSERT_NON_NULL (__rhs != nullptr , " operator==(basic_string, char*): received nullptr" );
3863
+
3864
+ using _String = basic_string<_CharT, _Traits, _Allocator>;
3865
+
3863
3866
size_t __rhs_len = _Traits::length (__rhs);
3867
+ if (__builtin_constant_p (__rhs_len) && !_String::__fits_in_sso (__rhs_len)) {
3868
+ if (!__lhs.__is_long ())
3869
+ return false ;
3870
+ }
3864
3871
if (__rhs_len != __lhs.size ())
3865
3872
return false ;
3866
3873
return __lhs.compare (0 , _String::npos, __rhs, __rhs_len) == 0 ;
3867
- #endif
3868
3874
}
3869
3875
3870
3876
#if _LIBCPP_STD_VER >= 20
0 commit comments