Skip to content

Commit

Permalink
Use _Memmove_meow as we use it ouside of copy algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
miscco committed Oct 12, 2020
1 parent 8a9f343 commit ae2dfb1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion stl/inc/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,7 @@ namespace ranges {
_NODISCARD constexpr _It2 _Move_backward_common(const _It1 _First, _It1 _Last, _It2 _Result) {
if constexpr (_Memmove_in_move_is_safe<_It1, _It2>) {
if (!_STD is_constant_evaluated()) {
return _Copy_backward_memmove(_First, _Last, _Result);
return _Memmove_backward(_First, _Last, _Result);
}
}

Expand Down
18 changes: 9 additions & 9 deletions stl/inc/memory
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ namespace ranges {
_STL_INTERNAL_STATIC_ASSERT(constructible_from<iter_value_t<_Out>, iter_reference_t<_It>>);

if constexpr (is_same_v<_Se, _It> && _Memmove_in_uninitialized_copy_is_safe<_It, _Out>) {
return _Copy_memcpy_common(_IFirst, _ILast, _OFirst, _OLast);
return _Memmove_forward_common(_IFirst, _ILast, _OFirst, _OLast);
} else {
_Uninitialized_backout _Backout{_STD move(_OFirst)};

Expand Down Expand Up @@ -138,7 +138,7 @@ _NoThrowFwdIt uninitialized_copy_n(const _InIt _First, const _Diff _Count_raw, _
auto _UFirst = _Get_unwrapped_n(_First, _Count);
auto _UDest = _Get_unwrapped_n(_Dest, _Count);
if constexpr (_Memmove_in_uninitialized_copy_is_safe<decltype(_UFirst), decltype(_UDest)>) {
_UDest = _Copy_memmove(_UFirst, _UFirst + _Count, _UDest);
_UDest = _Memmove_forward(_UFirst, _UFirst + _Count, _UDest);
} else {
_Uninitialized_backout<decltype(_UDest)> _Backout{_UDest};

Expand Down Expand Up @@ -168,7 +168,7 @@ _NoThrowFwdIt _Uninitialized_copy_n_unchecked2(_InIt _First, _Diff _Count, const
template <class _InIt, class _Diff, class _NoThrowFwdIt>
_NoThrowFwdIt _Uninitialized_copy_n_unchecked2(const _InIt _First, const _Diff _Count, const _NoThrowFwdIt _Dest,
true_type) { // copy [_First, _First + _Count) to [_Dest, ...), memmove optimization
return _Copy_memmove(_First, _First + _Count, _Dest);
return _Memmove_forward(_First, _First + _Count, _Dest);
}

template <class _InIt, class _Diff, class _NoThrowFwdIt>
Expand Down Expand Up @@ -214,7 +214,7 @@ namespace ranges {
auto _OFirst = _Get_unwrapped(_STD move(_First2));
const auto _OLast = _Get_unwrapped(_STD move(_Last2));
if constexpr (_Memmove_in_uninitialized_copy_is_safe<_It, _Out>) {
_OFirst = _Copy_memcpy_common(_IFirst, _IFirst + _Count, _OFirst, _OLast);
_OFirst = _Memmove_forward_common(_IFirst, _IFirst + _Count, _OFirst, _OLast);
} else {
_Uninitialized_backout _Backout{_STD move(_OFirst)};

Expand Down Expand Up @@ -301,7 +301,7 @@ namespace ranges {
_STL_INTERNAL_STATIC_ASSERT(constructible_from<iter_value_t<_Out>, iter_rvalue_reference_t<_It>>);

if constexpr (is_same_v<_Se, _It> && _Memmove_in_uninitialized_move_is_safe<_It, _Out>) {
return _Copy_memcpy_common(_IFirst, _ILast, _OFirst, _OLast);
return _Memmove_forward_common(_IFirst, _ILast, _OFirst, _OLast);
} else {
_Uninitialized_backout _Backout{_STD move(_OFirst)};

Expand Down Expand Up @@ -330,7 +330,7 @@ pair<_InIt, _NoThrowFwdIt> uninitialized_move_n(_InIt _First, const _Diff _Count
auto _UFirst = _Get_unwrapped_n(_First, _Count);
auto _UDest = _Get_unwrapped_n(_Dest, _Count);
if constexpr (_Memmove_in_uninitialized_move_is_safe<decltype(_UFirst), decltype(_UDest)>) {
_UDest = _Copy_memmove(_UFirst, _UFirst + _Count, _UDest);
_UDest = _Memmove_forward(_UFirst, _UFirst + _Count, _UDest);
_UFirst += _Count;
} else {
_Uninitialized_backout<decltype(_UDest)> _Backout{_UDest};
Expand Down Expand Up @@ -375,7 +375,7 @@ namespace ranges {
auto _OFirst = _Get_unwrapped(_STD move(_First2));
const auto _OLast = _Get_unwrapped(_STD move(_Last2));
if constexpr (_Memmove_in_uninitialized_move_is_safe<_It, _Out>) {
_OFirst = _Copy_memcpy_common(_IFirst, _IFirst + _Count, _OFirst, _OLast);
_OFirst = _Memmove_forward_common(_IFirst, _IFirst + _Count, _OFirst, _OLast);
} else {
_Uninitialized_backout _Backout{_STD move(_OFirst)};

Expand Down Expand Up @@ -2316,7 +2316,7 @@ struct _Reverse_destroy_multidimensional_n_guard {
template <class _Ty, size_t _Size>
void _Uninitialized_copy_multidimensional(const _Ty (&_In)[_Size], _Ty (&_Out)[_Size]) {
if constexpr (is_trivial_v<_Ty>) {
_Copy_memmove(_In, _In + _Size, _Out);
_Memmove_forward(_In, _In + _Size, _Out);
} else if constexpr (is_array_v<_Ty>) {
_Reverse_destroy_multidimensional_n_guard<_Ty> _Guard{_Out, 0};
for (size_t& _Idx = _Guard._Index; _Idx < _Size; ++_Idx) {
Expand Down Expand Up @@ -2639,7 +2639,7 @@ template <class _Ty, size_t _Size, class _Alloc>
void _Uninitialized_copy_multidimensional_al(const _Ty (&_In)[_Size], _Ty (&_Out)[_Size], _Alloc& _Al) {
using _Item = remove_all_extents_t<_Ty>;
if constexpr (conjunction_v<is_trivial<_Ty>, _Uses_default_construct<_Alloc, _Item*, const _Item&>>) {
_Copy_memmove(_In, _In + _Size, _Out);
_Memmove_forward(_In, _In + _Size, _Out);
} else if constexpr (is_array_v<_Ty>) {
_Reverse_destroy_multidimensional_n_al_guard<_Ty, _Alloc> _Guard{_Out, 0, _Al};
for (size_t& _Idx = _Guard._Index; _Idx < _Size; ++_Idx) {
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/vector
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ private:
_Clear_and_reserve_geometric(_Newsize);
}

_Mylast = _Refancy<pointer>(_Copy_memmove(_Unfancy(_First), _Unfancy(_Last), _Unfancy(_Myfirst)));
_Mylast = _Refancy<pointer>(_Memmove_forward(_Unfancy(_First), _Unfancy(_Last), _Unfancy(_Myfirst)));
} else
#endif // _HAS_IF_CONSTEXPR
{
Expand Down Expand Up @@ -1116,7 +1116,7 @@ private:
_Clear_and_reserve_geometric(_Newsize);
}

_Mylast = _Refancy<pointer>(_Copy_memmove(_First, _Last, _Unfancy(_Myfirst)));
_Mylast = _Refancy<pointer>(_Memmove_forward(_First, _Last, _Unfancy(_Myfirst)));
} else
#endif // _HAS_IF_CONSTEXPR
{
Expand Down
16 changes: 8 additions & 8 deletions stl/inc/xmemory
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,7 @@ template <class _InIt, class _NoThrowFwdIt>
_NoThrowFwdIt _Uninitialized_move_unchecked(_InIt _First, const _InIt _Last, _NoThrowFwdIt _Dest) {
// move [_First, _Last) to raw [_Dest, ...)
if constexpr (_Memmove_in_uninitialized_move_is_safe<_InIt, _NoThrowFwdIt>) {
return _Copy_memmove(_First, _Last, _Dest);
return _Memmove_forward(_First, _Last, _Dest);
} else {
_Uninitialized_backout<_NoThrowFwdIt> _Backout{_Dest};
for (; _First != _Last; ++_First) {
Expand All @@ -1507,7 +1507,7 @@ template <class _InIt, class _NoThrowFwdIt>
_NoThrowFwdIt _Uninitialized_move_unchecked1(
const _InIt _First, const _InIt _Last, const _NoThrowFwdIt _Dest, true_type) {
// move [_First, _Last) to raw [_Dest, ...), memmove optimization
return _Copy_memmove(_First, _Last, _Dest);
return _Memmove_forward(_First, _Last, _Dest);
}

template <class _InIt, class _NoThrowFwdIt>
Expand Down Expand Up @@ -1564,7 +1564,7 @@ _Alloc_ptr_t<_Alloc> _Uninitialized_copy(

if constexpr (conjunction_v<bool_constant<_Memmove_in_uninitialized_copy_is_safe<decltype(_UFirst), _Ptrval>>,
_Uses_default_construct<_Alloc, _Ptrval, decltype(*_UFirst)>>) {
_Copy_memmove(_UFirst, _ULast, _Unfancy(_Dest));
_Memmove_forward(_UFirst, _ULast, _Unfancy(_Dest));
_Dest += _ULast - _UFirst;
} else {
_Uninitialized_backout_al<_Alloc> _Backout{_Dest, _Al};
Expand Down Expand Up @@ -1594,7 +1594,7 @@ template <class _InIt, class _Alloc>
_Alloc_ptr_t<_Alloc> _Uninitialized_copy_al_unchecked(
const _InIt _First, const _InIt _Last, const _Alloc_ptr_t<_Alloc> _Dest, _Alloc&, true_type) {
// copy [_First, _Last) to raw _Dest, using default _Alloc construct, memmove optimization
return _Copy_memmove(_First, _Last, _Unfancy(_Dest));
return _Memmove_forward(_First, _Last, _Unfancy(_Dest));
}

template <class _InIt, class _Alloc>
Expand Down Expand Up @@ -1625,7 +1625,7 @@ _NoThrowFwdIt uninitialized_copy(const _InIt _First, const _InIt _Last, _NoThrow
const auto _ULast = _Get_unwrapped(_Last);
auto _UDest = _Get_unwrapped_n(_Dest, _Idl_distance<_InIt>(_UFirst, _ULast));
if constexpr (_Memmove_in_uninitialized_copy_is_safe<decltype(_UFirst), decltype(_UDest)>) {
_UDest = _Copy_memmove(_UFirst, _ULast, _UDest);
_UDest = _Memmove_forward(_UFirst, _ULast, _UDest);
} else {
_Uninitialized_backout<decltype(_UDest)> _Backout{_UDest};
for (; _UFirst != _ULast; ++_UFirst) {
Expand Down Expand Up @@ -1654,7 +1654,7 @@ template <class _InIt, class _NoThrowFwdIt>
_NoThrowFwdIt _Uninitialized_copy_unchecked(
const _InIt _First, const _InIt _Last, const _NoThrowFwdIt _Dest, true_type) {
// copy [_First, _Last) to raw [_Dest, ...), memmove optimization
return _Copy_memmove(_First, _Last, _Dest);
return _Memmove_forward(_First, _Last, _Dest);
}

template <class _InIt, class _NoThrowFwdIt>
Expand Down Expand Up @@ -1683,7 +1683,7 @@ _Alloc_ptr_t<_Alloc> _Uninitialized_move(
const auto _ULast = _Get_unwrapped(_Last);
if constexpr (conjunction_v<bool_constant<_Memmove_in_uninitialized_move_is_safe<decltype(_UFirst), _Ptrval>>,
_Uses_default_construct<_Alloc, _Ptrval, decltype(_STD move(*_UFirst))>>) {
_Copy_memmove(_UFirst, _ULast, _Unfancy(_Dest));
_Memmove_forward(_UFirst, _ULast, _Unfancy(_Dest));
return _Dest + (_ULast - _UFirst);
} else {
_Uninitialized_backout_al<_Alloc> _Backout{_Dest, _Al};
Expand Down Expand Up @@ -1711,7 +1711,7 @@ template <class _InIt, class _Alloc>
_Alloc_ptr_t<_Alloc> _Uninitialized_move_al_unchecked(
const _InIt _First, const _InIt _Last, _Alloc_ptr_t<_Alloc> _Dest, _Alloc&, true_type) {
// move [_First, _Last) to raw _Dest, using default _Alloc construct, memmove optimization
_Copy_memmove(_First, _Last, _Unfancy(_Dest));
_Memmove_forward(_First, _Last, _Unfancy(_Dest));
return _Dest + (_Last - _First);
}

Expand Down
36 changes: 18 additions & 18 deletions stl/inc/xutility
Original file line number Diff line number Diff line change
Expand Up @@ -4408,7 +4408,7 @@ _INLINE_VAR constexpr bool _Memmove_in_uninitialized_move_is_safe =
_Can_memop<remove_const_t<_IterSource>, _IterDest, _Memop_cat::_Move_uninitialized>;

template <class _InIt, class _OutIt>
_OutIt _Copy_memmove(_InIt _First, _InIt _Last, _OutIt _Dest) {
_OutIt _Memmove_forward(_InIt _First, _InIt _Last, _OutIt _Dest) {
const char* const _First_ch = const_cast<const char*>(reinterpret_cast<const volatile char*>(_First));
const char* const _Last_ch = const_cast<const char*>(reinterpret_cast<const volatile char*>(_Last));
char* const _Dest_ch = const_cast<char*>(reinterpret_cast<volatile char*>(_Dest));
Expand All @@ -4418,18 +4418,18 @@ _OutIt _Copy_memmove(_InIt _First, _InIt _Last, _OutIt _Dest) {
}

template <class _InIt, class _OutIt>
_OutIt _Copy_memmove(move_iterator<_InIt> _First, move_iterator<_InIt> _Last, _OutIt _Dest) {
return _Copy_memmove(_First.base(), _Last.base(), _Dest);
_OutIt _Memmove_forward(move_iterator<_InIt> _First, move_iterator<_InIt> _Last, _OutIt _Dest) {
return _Memmove_forward(_First.base(), _Last.base(), _Dest);
}

template <class _InIt, class _OutIt>
_OutIt _Copy_memcpy_common(_InIt _IFirst, _InIt _ILast, _OutIt _OFirst, _OutIt _OLast) noexcept {
_OutIt _Memmove_forward_common(_InIt _IFirst, _InIt _ILast, _OutIt _OFirst, _OutIt _OLast) noexcept {
const auto _IFirst_ch = const_cast<const char*>(reinterpret_cast<const volatile char*>(_IFirst));
const auto _ILast_ch = const_cast<const char*>(reinterpret_cast<const volatile char*>(_ILast));
const auto _OFirst_ch = const_cast<char*>(reinterpret_cast<volatile char*>(_OFirst));
const auto _OLast_ch = const_cast<const char*>(reinterpret_cast<const volatile char*>(_OLast));
const auto _Count = static_cast<size_t>((_STD min)(_ILast_ch - _IFirst_ch, _OLast_ch - _OFirst_ch));
_CSTD memcpy(_OFirst_ch, _IFirst_ch, _Count);
_CSTD memmove(_OFirst_ch, _IFirst_ch, _Count);
return reinterpret_cast<_OutIt>(_OFirst_ch + _Count);
}

Expand All @@ -4447,7 +4447,7 @@ _CONSTEXPR20 _OutIt _Copy_unchecked(_InIt _First, _InIt _Last, _OutIt _Dest) {
if (!_STD is_constant_evaluated())
#endif // __cpp_lib_is_constant_evaluated
{
return _Copy_memmove(_First, _Last, _Dest);
return _Memmove_forward(_First, _Last, _Dest);
}
}

Expand All @@ -4471,7 +4471,7 @@ _OutIt _Copy_unchecked1(_InIt _First, _InIt _Last, _OutIt _Dest, false_type) {
template <class _InIt, class _OutIt>
_OutIt _Copy_unchecked1(_InIt _First, _InIt _Last, _OutIt _Dest, true_type) {
// copy [_First, _Last) to [_Dest, ...), pointers to trivially copyable
return _Copy_memmove(_First, _Last, _Dest);
return _Memmove_forward(_First, _Last, _Dest);
}

template <class _InIt, class _OutIt>
Expand Down Expand Up @@ -4517,7 +4517,7 @@ _CONSTEXPR20 _OutIt copy_n(_InIt _First, _Diff _Count_raw, _OutIt _Dest) {
if (!_STD is_constant_evaluated())
#endif // __cpp_lib_is_constant_evaluated
{
_UDest = _Copy_memmove(_UFirst, _UFirst + _Count, _UDest);
_UDest = _Memmove_forward(_UFirst, _UFirst + _Count, _UDest);
_Seek_wrapped(_Dest, _UDest);
return _Dest;
}
Expand Down Expand Up @@ -4563,7 +4563,7 @@ template <class _InIt, class _Diff, class _OutIt>
_OutIt _Copy_n_unchecked4(_InIt _First, _Diff _Count, _OutIt _Dest, true_type) {
// copy [_First, _First + _Count) to [_Dest, ...), memmove optimization
// pre: 0 < _Count
return _Copy_memmove(_First, _First + _Count, _Dest);
return _Memmove_forward(_First, _First + _Count, _Dest);
}

template <class _InIt, class _Diff, class _OutIt>
Expand Down Expand Up @@ -4593,7 +4593,7 @@ _FwdIt2 copy_n(_ExPo&&, _FwdIt1 _First, _Diff _Count_raw, _FwdIt2 _Dest) noexcep

// FUNCTION TEMPLATE copy_backward
template <class _BidIt1, class _BidIt2>
_BidIt2 _Copy_backward_memmove(_BidIt1 _First, _BidIt1 _Last, _BidIt2 _Dest) {
_BidIt2 _Memmove_backward(_BidIt1 _First, _BidIt1 _Last, _BidIt2 _Dest) {
// implement copy_backward-like function as memmove
const char* const _First_ch = const_cast<const char*>(reinterpret_cast<const volatile char*>(_First));
const char* const _Last_ch = const_cast<const char*>(reinterpret_cast<const volatile char*>(_Last));
Expand All @@ -4603,8 +4603,8 @@ _BidIt2 _Copy_backward_memmove(_BidIt1 _First, _BidIt1 _Last, _BidIt2 _Dest) {
}

template <class _BidIt1, class _BidIt2>
_BidIt2 _Copy_backward_memmove(move_iterator<_BidIt1> _First, move_iterator<_BidIt1> _Last, _BidIt2 _Dest) {
return _Copy_backward_memmove(_First.base(), _Last.base(), _Dest);
_BidIt2 _Memmove_backward(move_iterator<_BidIt1> _First, move_iterator<_BidIt1> _Last, _BidIt2 _Dest) {
return _Memmove_backward(_First.base(), _Last.base(), _Dest);
}

#if _HAS_IF_CONSTEXPR
Expand All @@ -4616,7 +4616,7 @@ _NODISCARD _CONSTEXPR20 _BidIt2 _Copy_backward_unchecked(_BidIt1 _First, _BidIt1
if (!_STD is_constant_evaluated())
#endif // __cpp_lib_is_constant_evaluated
{
return _Copy_backward_memmove(_First, _Last, _Dest);
return _Memmove_backward(_First, _Last, _Dest);
}
}

Expand Down Expand Up @@ -4651,7 +4651,7 @@ _BidIt2 _Copy_backward_unchecked(_BidIt1 _First, _BidIt1 _Last, _BidIt2 _Dest, f
template <class _BidIt1, class _BidIt2>
_BidIt2 _Copy_backward_unchecked(_BidIt1 _First, _BidIt1 _Last, _BidIt2 _Dest, true_type) {
// copy [_First, _Last) backwards to [..., _Dest), memmove optimization
return _Copy_backward_memmove(_First, _Last, _Dest);
return _Memmove_backward(_First, _Last, _Dest);
}

template <class _BidIt1, class _BidIt2>
Expand Down Expand Up @@ -4686,7 +4686,7 @@ _CONSTEXPR20 _OutIt _Move_unchecked(_InIt _First, _InIt _Last, _OutIt _Dest) {
if (!_STD is_constant_evaluated())
#endif // __cpp_lib_is_constant_evaluated
{
return _Copy_memmove(_First, _Last, _Dest);
return _Memmove_forward(_First, _Last, _Dest);
}
}

Expand All @@ -4710,7 +4710,7 @@ _OutIt _Move_unchecked1(_InIt _First, _InIt _Last, _OutIt _Dest, false_type) {
template <class _InIt, class _OutIt>
_OutIt _Move_unchecked1(_InIt _First, _InIt _Last, _OutIt _Dest, true_type) {
// move [_First, _Last) to [_Dest, ...), memmove optimization
return _Copy_memmove(_First, _Last, _Dest);
return _Memmove_forward(_First, _Last, _Dest);
}

template <class _InIt, class _OutIt>
Expand Down Expand Up @@ -4754,7 +4754,7 @@ _CONSTEXPR20 _BidIt2 _Move_backward_unchecked(_BidIt1 _First, _BidIt1 _Last, _Bi
if (!_STD is_constant_evaluated())
#endif // __cpp_lib_is_constant_evaluated
{
return _Copy_backward_memmove(_First, _Last, _Dest);
return _Memmove_backward(_First, _Last, _Dest);
}
}

Expand All @@ -4778,7 +4778,7 @@ _BidIt2 _Move_backward_unchecked1(_BidIt1 _First, _BidIt1 _Last, _BidIt2 _Dest,
template <class _BidIt1, class _BidIt2>
_BidIt2 _Move_backward_unchecked1(_BidIt1 _First, _BidIt1 _Last, _BidIt2 _Dest, true_type) {
// move [_First, _Last) backwards to [..., _Dest), memmove optimization
return _Copy_backward_memmove(_First, _Last, _Dest);
return _Memmove_backward(_First, _Last, _Dest);
}

template <class _BidIt1, class _BidIt2>
Expand Down

0 comments on commit ae2dfb1

Please sign in to comment.