Skip to content

Commit 9ba4a22

Browse files
authored
vector_algorithms.cpp: avoid cast to integral in __std_bitset_from_string_N (#5759)
1 parent 5f63382 commit 9ba4a22

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

stl/src/vector_algorithms.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7096,8 +7096,6 @@ namespace {
70967096
};
70977097

70987098
struct _Traits_1_avx : _Traits_avx {
7099-
using _Word = uint32_t;
7100-
71017099
static __m256i _Set(const char _Val) noexcept {
71027100
return _mm256_set1_epi8(_Val);
71037101
}
@@ -7117,8 +7115,6 @@ namespace {
71177115
};
71187116

71197117
struct _Traits_1_sse : _Traits_sse {
7120-
using _Word = uint16_t;
7121-
71227118
static __m128i _Set(const char _Val) noexcept {
71237119
return _mm_shuffle_epi8(_mm_cvtsi32_si128(_Val), _mm_setzero_si128());
71247120
}
@@ -7135,8 +7131,6 @@ namespace {
71357131
};
71367132

71377133
struct _Traits_2_avx : _Traits_avx {
7138-
using _Word = uint16_t;
7139-
71407134
static __m256i _Set(const wchar_t _Val) noexcept {
71417135
return _mm256_set1_epi16(_Val);
71427136
}
@@ -7156,8 +7150,6 @@ namespace {
71567150
};
71577151

71587152
struct _Traits_2_sse : _Traits_sse {
7159-
using _Word = uint8_t;
7160-
71617153
static __m128i _Set(const wchar_t _Val) noexcept {
71627154
return _mm_set1_epi16(_Val);
71637155
}
@@ -7205,19 +7197,19 @@ namespace {
72057197
}
72067198

72077199
template <class _Traits, class _Elem>
7208-
bool _Impl(void* const _Dest, const _Elem* const _Src, const size_t _Size_bytes, const size_t _Size_bits,
7200+
bool _Impl(void* _Dest, const _Elem* const _Src, const size_t _Size_bytes, const size_t _Size_bits,
72097201
const size_t _Size_chars, const _Elem _Elem0, const _Elem _Elem1) noexcept {
72107202
[[maybe_unused]] typename _Traits::_Guard _Guard; // TRANSITION, DevCom-10331414
72117203
const auto _Dx0 = _Traits::_Set(_Elem0);
72127204
const auto _Dx1 = _Traits::_Set(_Elem1);
72137205

7214-
auto _Dst_words = reinterpret_cast<_Traits::_Word*>(_Dest);
7215-
void* _Dst_words_end = _Dst_words;
7216-
_Advance_bytes(_Dst_words_end, _Size_bytes);
7206+
void* _Dest_end = _Dest;
7207+
_Advance_bytes(_Dest_end, _Size_bytes);
72177208

7218-
auto _Out = [&_Dst_words](const _Traits::_Vec _Ex1) {
7219-
*_Dst_words = _Traits::_To_bits(_Ex1);
7220-
++_Dst_words;
7209+
auto _Out = [&_Dest](const _Traits::_Vec _Ex1) {
7210+
const auto _Val = _Traits::_To_bits(_Ex1);
7211+
memcpy(_Dest, &_Val, sizeof(_Val));
7212+
_Advance_bytes(_Dest, sizeof(_Val));
72217213
};
72227214

72237215
const size_t _Size_convert = (_Size_chars <= _Size_bits) ? _Size_chars : _Size_bits;
@@ -7234,8 +7226,8 @@ namespace {
72347226
}
72357227

72367228
// Trim tail (may be padding tail, or too short string, or both)
7237-
if (_Dst_words != _Dst_words_end) {
7238-
memset(_Dst_words, 0, _Byte_length(_Dst_words, _Dst_words_end));
7229+
if (_Dest != _Dest_end) {
7230+
memset(_Dest, 0, _Byte_length(_Dest, _Dest_end));
72397231
}
72407232

72417233
return true;

0 commit comments

Comments
 (0)