From: Nikolas Klauser Date: Tue, 30 Aug 2022 15:43:14 +0000 (+0200) Subject: [libc++][NFC] Copy the whole union instead of a member; also remove __zero() X-Git-Tag: upstream/17.0.6~34567 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c747bd0e2339b6d471e2ceadb7f7825970b711bd;p=platform%2Fupstream%2Fllvm.git [libc++][NFC] Copy the whole union instead of a member; also remove __zero() This doesn't affect code-gen Reviewed By: ldionne, #libc Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D132951 --- diff --git a/libcxx/include/string b/libcxx/include/string index a7bd438..d89eccb 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -812,7 +812,7 @@ private: if (__size > max_size()) __throw_length_error(); if (__fits_in_sso(__size)) { - __zero(); + __r_.first() = __rep(); __set_short_size(__size); } else { auto __capacity = __recommend(__size) + 1; @@ -1531,7 +1531,7 @@ private: } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __default_init() { - __zero(); + __r_.first() = __rep(); if (__libcpp_is_constant_evaluated()) { size_type __sz = __recommend(0) + 1; pointer __ptr = __alloc_traits::allocate(__alloc(), __sz); @@ -1638,11 +1638,6 @@ private: const_pointer __get_pointer() const _NOEXCEPT {return __is_long() ? __get_long_pointer() : __get_short_pointer();} - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 - void __zero() _NOEXCEPT { - __r_.first() = __rep(); - } - template static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type __align_it(size_type __s) _NOEXCEPT @@ -1942,7 +1937,7 @@ void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __reserve) { if (__libcpp_is_constant_evaluated()) - __zero(); + __r_.first() = __rep(); if (__reserve > max_size()) __throw_length_error(); pointer __p; @@ -1970,7 +1965,7 @@ void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz) { if (__libcpp_is_constant_evaluated()) - __zero(); + __r_.first() = __rep(); if (__sz > max_size()) __throw_length_error(); pointer __p; @@ -2029,7 +2024,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc())) { if (!__str.__is_long()) - __r_.first().__r = __str.__r_.first().__r; + __r_.first() = __str.__r_.first(); else __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); @@ -2043,7 +2038,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string( : __r_(__default_init_tag(), __a) { if (!__str.__is_long()) - __r_.first().__r = __str.__r_.first().__r; + __r_.first() = __str.__r_.first(); else __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); @@ -2055,7 +2050,8 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external( const value_type* __s, size_type __sz) { if (__libcpp_is_constant_evaluated()) - __zero(); + __r_.first() = __rep(); + pointer __p; if (__fits_in_sso(__sz)) { __p = __get_short_pointer(); @@ -2100,12 +2096,9 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, co __init(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); else { - if (__libcpp_is_constant_evaluated()) { - __zero(); - __r_.first().__l = __str.__r_.first().__l; - } else { - __r_.first().__r = __str.__r_.first().__r; - } + if (__libcpp_is_constant_evaluated()) + __r_.first() = __rep(); + __r_.first() = __str.__r_.first(); __str.__default_init(); } std::__debug_db_insert_c(this); @@ -2121,7 +2114,8 @@ void basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c) { if (__libcpp_is_constant_evaluated()) - __zero(); + __r_.first() = __rep(); + if (__n > max_size()) __throw_length_error(); pointer __p; @@ -2261,7 +2255,7 @@ __enable_if_t basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last) { if (__libcpp_is_constant_evaluated()) - __zero(); + __r_.first() = __rep(); size_type __sz = static_cast(std::distance(__first, __last)); if (__sz > max_size()) __throw_length_error(); @@ -2517,7 +2511,7 @@ basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) __copy_assign_alloc(__str); if (!__is_long()) { if (!__str.__is_long()) { - __r_.first().__r = __str.__r_.first().__r; + __r_.first() = __str.__r_.first(); } else { return __assign_no_alias(__str.data(), __str.size()); }