|
9 | 9 | #if _STL_COMPILER_PREPROCESSOR
|
10 | 10 | #include <cstddef>
|
11 | 11 | #include <cstdint>
|
12 |
| -#include <cstring> |
13 | 12 | #include <xtr1common>
|
14 | 13 |
|
15 | 14 | #pragma pack(push, _CRT_PACKING)
|
@@ -2513,21 +2512,31 @@ void _Swap_trivial_arrays(_Ty (&_Left)[_Size], _Ty (&_Right)[_Size]) noexcept {
|
2513 | 2512 | if constexpr (_Size_parts != 0) {
|
2514 | 2513 | const auto _Stop = _Left_ptr + _Size_parts;
|
2515 | 2514 | do {
|
2516 |
| - unsigned char _Buf[_Part_size_bytes]; |
2517 |
| - _CSTD memcpy(_Buf, _Left_ptr, _Part_size_bytes); |
2518 |
| - _CSTD memcpy(_Left_ptr, _Right_ptr, _Part_size_bytes); |
2519 |
| - _CSTD memcpy(_Right_ptr, _Buf, _Part_size_bytes); |
| 2515 | + struct _Buffer_type { |
| 2516 | + unsigned char _Data[_Part_size_bytes]; |
| 2517 | + }; |
| 2518 | + |
| 2519 | + _STL_INTERNAL_STATIC_ASSERT(sizeof(_Buffer_type) == _Part_size_bytes); // assume no padding |
| 2520 | + |
| 2521 | + const _Buffer_type _Buffer = *reinterpret_cast<const _Buffer_type*>(_Left_ptr); |
| 2522 | + *reinterpret_cast<_Buffer_type*>(_Left_ptr) = *reinterpret_cast<const _Buffer_type*>(_Right_ptr); |
| 2523 | + *reinterpret_cast<_Buffer_type*>(_Right_ptr) = _Buffer; |
2520 | 2524 | _Left_ptr += _Part_size_bytes;
|
2521 | 2525 | _Right_ptr += _Part_size_bytes;
|
2522 | 2526 |
|
2523 | 2527 | } while (_Left_ptr != _Stop);
|
2524 | 2528 | }
|
2525 | 2529 |
|
2526 | 2530 | if constexpr (_Size_tail != 0) {
|
2527 |
| - unsigned char _Buf[_Size_tail]; |
2528 |
| - _CSTD memcpy(_Buf, _Left_ptr, _Size_tail); |
2529 |
| - _CSTD memcpy(_Left_ptr, _Right_ptr, _Size_tail); |
2530 |
| - _CSTD memcpy(_Right_ptr, _Buf, _Size_tail); |
| 2531 | + struct _Last_buffer_type { |
| 2532 | + unsigned char _Data[_Size_tail]; |
| 2533 | + }; |
| 2534 | + |
| 2535 | + _STL_INTERNAL_STATIC_ASSERT(sizeof(_Last_buffer_type) == _Size_tail); // assume no padding |
| 2536 | + |
| 2537 | + const _Last_buffer_type _Last_buffer = *reinterpret_cast<const _Last_buffer_type*>(_Left_ptr); |
| 2538 | + *reinterpret_cast<_Last_buffer_type*>(_Left_ptr) = *reinterpret_cast<const _Last_buffer_type*>(_Right_ptr); |
| 2539 | + *reinterpret_cast<_Last_buffer_type*>(_Right_ptr) = _Last_buffer; |
2531 | 2540 | }
|
2532 | 2541 | }
|
2533 | 2542 |
|
|
0 commit comments