forked from OSchip/llvm-project
Optimize and fix basic_string move assignment operator. Reviewed as https://reviews.llvm.org/D68623. Thanks to mvels for the patch.
This commit is contained in:
parent
f59614d906
commit
703c26f03b
|
@ -2289,10 +2289,20 @@ basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, tr
|
||||||
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
|
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
__clear_and_shrink();
|
if (__is_long()) {
|
||||||
__r_.first() = __str.__r_.first();
|
__alloc_traits::deallocate(__alloc(), __get_long_pointer(),
|
||||||
__move_assign_alloc(__str);
|
__get_long_cap());
|
||||||
__str.__zero();
|
#if _LIBCPP_STD_VER <= 14
|
||||||
|
if (!is_nothrow_move_assignable<allocator_type>::value) {
|
||||||
|
__set_short_size(0);
|
||||||
|
traits_type::assign(__get_short_pointer()[0], value_type());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
__move_assign_alloc(__str);
|
||||||
|
__r_.first() = __str.__r_.first();
|
||||||
|
__str.__set_short_size(0);
|
||||||
|
traits_type::assign(__str.__get_short_pointer()[0], value_type());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class _CharT, class _Traits, class _Allocator>
|
template <class _CharT, class _Traits, class _Allocator>
|
||||||
|
|
Loading…
Reference in New Issue