[libcxx-commits] [libcxx] c747bd0 - [libc++][NFC] Copy the whole union instead of a member; also remove __zero()
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Sep 2 12:45:05 PDT 2022
Author: Nikolas Klauser
Date: 2022-09-02T21:44:57+02:00
New Revision: c747bd0e2339b6d471e2ceadb7f7825970b711bd
URL: https://github.com/llvm/llvm-project/commit/c747bd0e2339b6d471e2ceadb7f7825970b711bd
DIFF: https://github.com/llvm/llvm-project/commit/c747bd0e2339b6d471e2ceadb7f7825970b711bd.diff
LOG: [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
Added:
Modified:
libcxx/include/string
Removed:
################################################################################
diff --git a/libcxx/include/string b/libcxx/include/string
index a7bd43853c24..d89eccb7cea9 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 <size_type __a> 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<size_type>(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<true>(__str.data(), __str.size());
}
More information about the libcxx-commits
mailing list