diff --git a/stl/inc/xstring b/stl/inc/xstring index b98faf0abf..e0611310c8 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -582,7 +582,7 @@ template constexpr int _Traits_compare(_In_reads_(_Left_size) const _Traits_ptr_t<_Traits> _Left, const size_t _Left_size, _In_reads_(_Right_size) const _Traits_ptr_t<_Traits> _Right, const size_t _Right_size) noexcept { // compare [_Left, _Left + _Left_size) to [_Right, _Right + _Right_size) using _Traits - const int _Ans = _Traits::compare(_Left, _Right, (_STD min) (_Left_size, _Right_size)); + const int _Ans = _Traits::compare(_Left, _Right, (_STD min)(_Left_size, _Right_size)); if (_Ans != 0) { return _Ans; @@ -653,11 +653,11 @@ constexpr size_t _Traits_rfind(_In_reads_(_Hay_size) const _Traits_ptr_t<_Traits const size_t _Needle_size) noexcept { // search [_Haystack, _Haystack + _Hay_size) for [_Needle, _Needle + _Needle_size) beginning before _Start_at if (_Needle_size == 0) { - return (_STD min) (_Start_at, _Hay_size); // empty string always matches + return (_STD min)(_Start_at, _Hay_size); // empty string always matches } if (_Needle_size <= _Hay_size) { // room for match, look for it - for (auto _Match_try = _Haystack + (_STD min) (_Start_at, _Hay_size - _Needle_size);; --_Match_try) { + for (auto _Match_try = _Haystack + (_STD min)(_Start_at, _Hay_size - _Needle_size);; --_Match_try) { if (_Traits::eq(*_Match_try, *_Needle) && _Traits::compare(_Match_try, _Needle, _Needle_size) == 0) { return static_cast(_Match_try - _Haystack); // found a match } @@ -676,7 +676,7 @@ constexpr size_t _Traits_rfind_ch(_In_reads_(_Hay_size) const _Traits_ptr_t<_Tra const size_t _Start_at, const _Traits_ch_t<_Traits> _Ch) noexcept { // search [_Haystack, _Haystack + _Hay_size) for _Ch before _Start_at if (_Hay_size != 0) { // room for match, look for it - for (auto _Match_try = _Haystack + (_STD min) (_Start_at, _Hay_size - 1);; --_Match_try) { + for (auto _Match_try = _Haystack + (_STD min)(_Start_at, _Hay_size - 1);; --_Match_try) { if (_Traits::eq(*_Match_try, _Ch)) { return static_cast(_Match_try - _Haystack); // found a match } @@ -741,41 +741,31 @@ private: bool _Matches[256] = {}; }; -template +template > constexpr size_t _Traits_find_first_of(_In_reads_(_Hay_size) const _Traits_ptr_t<_Traits> _Haystack, const size_t _Hay_size, const size_t _Start_at, _In_reads_(_Needle_size) const _Traits_ptr_t<_Traits> _Needle, - const size_t _Needle_size, false_type) noexcept { + const size_t _Needle_size) noexcept { // in [_Haystack, _Haystack + _Hay_size), look for one of [_Needle, _Needle + _Needle_size), at/after _Start_at - // general algorithm if (_Needle_size != 0 && _Start_at < _Hay_size) { // room for match, look for it - const auto _End = _Haystack + _Hay_size; - for (auto _Match_try = _Haystack + _Start_at; _Match_try < _End; ++_Match_try) { - if (_Traits::find(_Needle, _Needle_size, *_Match_try)) { - return static_cast(_Match_try - _Haystack); // found a match + if constexpr (_Special) { + _String_bitmap _Matches; + if (!_Matches._Mark(_Needle, _Needle + _Needle_size)) { // couldn't put one of the characters into the + // bitmap, fall back to the serial algorithm + return _Traits_find_first_of<_Traits, false>(_Haystack, _Hay_size, _Start_at, _Needle, _Needle_size); } - } - } - - return static_cast(-1); // no match -} -template -constexpr size_t _Traits_find_first_of(_In_reads_(_Hay_size) const _Traits_ptr_t<_Traits> _Haystack, - const size_t _Hay_size, const size_t _Start_at, _In_reads_(_Needle_size) const _Traits_ptr_t<_Traits> _Needle, - const size_t _Needle_size, true_type) noexcept { - // in [_Haystack, _Haystack + _Hay_size), look for one of [_Needle, _Needle + _Needle_size), at/after _Start_at - // special case for std::char_traits - if (_Needle_size != 0 && _Start_at < _Hay_size) { // room for match, look for it - _String_bitmap _Matches; - if (!_Matches._Mark(_Needle, _Needle + _Needle_size)) { // couldn't put one of the characters into the bitmap, - // fall back to the serial algorithm - return _Traits_find_first_of<_Traits>(_Haystack, _Hay_size, _Start_at, _Needle, _Needle_size, false_type{}); - } - - const auto _End = _Haystack + _Hay_size; - for (auto _Match_try = _Haystack + _Start_at; _Match_try < _End; ++_Match_try) { - if (_Matches._Match(*_Match_try)) { - return static_cast(_Match_try - _Haystack); // found a match + const auto _End = _Haystack + _Hay_size; + for (auto _Match_try = _Haystack + _Start_at; _Match_try < _End; ++_Match_try) { + if (_Matches._Match(*_Match_try)) { + return static_cast(_Match_try - _Haystack); // found a match + } + } + } else { + const auto _End = _Haystack + _Hay_size; + for (auto _Match_try = _Haystack + _Start_at; _Match_try < _End; ++_Match_try) { + if (_Traits::find(_Needle, _Needle_size, *_Match_try)) { + return static_cast(_Match_try - _Haystack); // found a match + } } } } @@ -790,7 +780,7 @@ constexpr size_t _Traits_find_last_of(_In_reads_(_Hay_size) const _Traits_ptr_t< // in [_Haystack, _Haystack + _Hay_size), look for last of [_Needle, _Needle + _Needle_size), before _Start_at // general algorithm if (_Needle_size != 0 && _Hay_size != 0) { // worth searching, do it - for (auto _Match_try = _Haystack + (_STD min) (_Start_at, _Hay_size - 1);; --_Match_try) { + for (auto _Match_try = _Haystack + (_STD min)(_Start_at, _Hay_size - 1);; --_Match_try) { if (_Traits::find(_Needle, _Needle_size, *_Match_try)) { return static_cast(_Match_try - _Haystack); // found a match } @@ -817,7 +807,7 @@ constexpr size_t _Traits_find_last_of(_In_reads_(_Hay_size) const _Traits_ptr_t< return _Traits_find_last_of<_Traits>(_Haystack, _Hay_size, _Start_at, _Needle, _Needle_size, false_type{}); } - for (auto _Match_try = _Haystack + (_STD min) (_Start_at, _Hay_size - 1);; --_Match_try) { + for (auto _Match_try = _Haystack + (_STD min)(_Start_at, _Hay_size - 1);; --_Match_try) { if (_Matches._Match(*_Match_try)) { return static_cast(_Match_try - _Haystack); // found a match } @@ -897,7 +887,7 @@ constexpr size_t _Traits_find_last_not_of(_In_reads_(_Hay_size) const _Traits_pt // in [_Haystack, _Haystack + _Hay_size), look for none of [_Needle, _Needle + _Needle_size), before _Start_at // general algorithm if (_Hay_size != 0) { // worth searching, do it - for (auto _Match_try = _Haystack + (_STD min) (_Start_at, _Hay_size - 1);; --_Match_try) { + for (auto _Match_try = _Haystack + (_STD min)(_Start_at, _Hay_size - 1);; --_Match_try) { if (!_Traits::find(_Needle, _Needle_size, *_Match_try)) { return static_cast(_Match_try - _Haystack); // found a match } @@ -925,7 +915,7 @@ constexpr size_t _Traits_find_last_not_of(_In_reads_(_Hay_size) const _Traits_pt _Haystack, _Hay_size, _Start_at, _Needle, _Needle_size, false_type{}); } - for (auto _Match_try = _Haystack + (_STD min) (_Start_at, _Hay_size - 1);; --_Match_try) { + for (auto _Match_try = _Haystack + (_STD min)(_Start_at, _Hay_size - 1);; --_Match_try) { if (!_Matches._Match(*_Match_try)) { return static_cast(_Match_try - _Haystack); // found a match } @@ -944,7 +934,7 @@ constexpr size_t _Traits_rfind_not_ch(_In_reads_(_Hay_size) const _Traits_ptr_t< const size_t _Hay_size, const size_t _Start_at, const _Traits_ch_t<_Traits> _Ch) noexcept { // search [_Haystack, _Haystack + _Hay_size) for any value other than _Ch before _Start_at if (_Hay_size != 0) { // room for match, look for it - for (auto _Match_try = _Haystack + (_STD min) (_Start_at, _Hay_size - 1);; --_Match_try) { + for (auto _Match_try = _Haystack + (_STD min)(_Start_at, _Hay_size - 1);; --_Match_try) { if (!_Traits::eq(*_Match_try, _Ch)) { return static_cast(_Match_try - _Haystack); // found a match } @@ -1371,7 +1361,7 @@ public: _NODISCARD constexpr size_type max_size() const noexcept { // bound to PTRDIFF_MAX to make end() - begin() well defined (also makes room for npos) // bound to static_cast(-1) / sizeof(_Elem) by address space limits - return (_STD min) (static_cast(PTRDIFF_MAX), static_cast(-1) / sizeof(_Elem)); + return (_STD min)(static_cast(PTRDIFF_MAX), static_cast(-1) / sizeof(_Elem)); } _NODISCARD constexpr const_reference operator[](const size_type _Off) const noexcept /* strengthened */ { @@ -1576,8 +1566,7 @@ public: _NODISCARD constexpr size_type find_first_of(const basic_string_view _Right, const size_type _Off = 0) const noexcept { // look for one of _Right at or after _Off - return _Traits_find_first_of<_Traits>( - _Mydata, _Mysize, _Off, _Right._Mydata, _Right._Mysize, _Is_specialization<_Traits, char_traits>{}); + return _Traits_find_first_of<_Traits>(_Mydata, _Mysize, _Off, _Right._Mydata, _Right._Mysize); } _NODISCARD constexpr size_type find_first_of(const _Elem _Ch, const size_type _Off = 0) const noexcept { @@ -1588,15 +1577,13 @@ public: _NODISCARD constexpr size_type find_first_of(_In_reads_(_Count) const _Elem* const _Ptr, const size_type _Off, const size_type _Count) const noexcept /* strengthened */ { // look for one of [_Ptr, _Ptr + _Count) at or after _Off - return _Traits_find_first_of<_Traits>( - _Mydata, _Mysize, _Off, _Ptr, _Count, _Is_specialization<_Traits, char_traits>{}); + return _Traits_find_first_of<_Traits>(_Mydata, _Mysize, _Off, _Ptr, _Count); } _NODISCARD constexpr size_type find_first_of( _In_z_ const _Elem* const _Ptr, const size_type _Off = 0) const noexcept /* strengthened */ { // look for one of [_Ptr, ) at or after _Off - return _Traits_find_first_of<_Traits>( - _Mydata, _Mysize, _Off, _Ptr, _Traits::length(_Ptr), _Is_specialization<_Traits, char_traits>{}); + return _Traits_find_first_of<_Traits>(_Mydata, _Mysize, _Off, _Ptr, _Traits::length(_Ptr)); } _NODISCARD constexpr size_type find_last_of(const basic_string_view _Right, @@ -1694,7 +1681,7 @@ private: constexpr size_type _Clamp_suffix_size(const size_type _Off, const size_type _Size) const noexcept { // trims _Size to the longest it can be assuming a string at/after _Off - return (_STD min) (_Size, _Mysize - _Off); + return (_STD min)(_Size, _Mysize - _Off); } [[noreturn]] static void _Xran() { @@ -2357,7 +2344,7 @@ public: _CONSTEXPR20 size_type _Clamp_suffix_size(const size_type _Off, const size_type _Size) const noexcept { // trims _Size to the longest it can be assuming a string at/after _Off - return (_STD min) (_Size, _Mysize - _Off); + return (_STD min)(_Size, _Mysize - _Off); } union _Bxty { // storage for small buffer or pointer to larger one @@ -2665,7 +2652,7 @@ public: if (_Activate_large_mode) { // we should never allocate less than _BUF_SIZE space (_New_size could be small if constant evaluated) - const size_type _Requested_size = (_STD max) (_New_size, _BUF_SIZE); + const size_type _Requested_size = (_STD max)(_New_size, _BUF_SIZE); _New_capacity = _Calculate_growth(_Requested_size, _BUF_SIZE - 1, max_size()); const pointer _Fancyptr = _Getal().allocate(_New_capacity + 1); // throws _Ptr = _Unfancy(_Fancyptr); @@ -2945,7 +2932,7 @@ private: } auto& _Al = _Getal(); - const size_type _New_capacity = (_STD min) (_Right_size | _ALLOC_MASK, max_size()); + const size_type _New_capacity = (_STD min)(_Right_size | _ALLOC_MASK, max_size()); const pointer _New_array = _Al.allocate(_New_capacity + 1); // throws _Construct_in_place(_My_data._Bx._Ptr, _New_array); @@ -3802,10 +3789,10 @@ public: } } - size_type _Target_capacity = (_STD min) (_My_data._Mysize | _ALLOC_MASK, max_size()); + size_type _Target_capacity = (_STD min)(_My_data._Mysize | _ALLOC_MASK, max_size()); #if _HAS_CXX20 // must allocate at least _BUF_SIZE space - _Target_capacity = (_STD max) (_Target_capacity, _BUF_SIZE); + _Target_capacity = (_STD max)(_Target_capacity, _BUF_SIZE); #endif // _HAS_CXX20 if (_Target_capacity < _My_data._Myres) { // worth shrinking, do it @@ -3943,8 +3930,8 @@ public: _NODISCARD _CONSTEXPR20 size_type max_size() const noexcept { const size_type _Alloc_max = _Alty_traits::max_size(_Getal()); const size_type _Storage_max = // can always store small string - (_STD max) (_Alloc_max, static_cast(_BUF_SIZE)); - return (_STD min) (static_cast((numeric_limits::max) ()), + (_STD max)(_Alloc_max, static_cast(_BUF_SIZE)); + return (_STD min)(static_cast((numeric_limits::max)()), _Storage_max - 1 // -1 is for null terminator and/or npos ); } @@ -4214,8 +4201,8 @@ public: noexcept(_Is_nothrow_convertible_v>) { // look for one of _Right at or after _Off basic_string_view<_Elem, _Traits> _As_view = _Right; - return static_cast(_Traits_find_first_of<_Traits>(_Mypair._Myval2._Myptr(), _Mypair._Myval2._Mysize, - _Off, _As_view.data(), _As_view.size(), _Is_specialization<_Traits, char_traits>{})); + return static_cast(_Traits_find_first_of<_Traits>( + _Mypair._Myval2._Myptr(), _Mypair._Myval2._Mysize, _Off, _As_view.data(), _As_view.size())); } #endif // _HAS_CXX17 @@ -4223,22 +4210,21 @@ public: const basic_string& _Right, const size_type _Off = 0) const noexcept { // look for one of _Right at or after _Off return static_cast(_Traits_find_first_of<_Traits>(_Mypair._Myval2._Myptr(), _Mypair._Myval2._Mysize, - _Off, _Right._Mypair._Myval2._Myptr(), _Right._Mypair._Myval2._Mysize, - _Is_specialization<_Traits, char_traits>{})); + _Off, _Right._Mypair._Myval2._Myptr(), _Right._Mypair._Myval2._Mysize)); } _NODISCARD _CONSTEXPR20 size_type find_first_of(_In_reads_(_Count) const _Elem* const _Ptr, const size_type _Off, const size_type _Count) const noexcept /* strengthened */ { // look for one of [_Ptr, _Ptr + _Count) at or after _Off - return static_cast(_Traits_find_first_of<_Traits>(_Mypair._Myval2._Myptr(), _Mypair._Myval2._Mysize, - _Off, _Ptr, _Count, _Is_specialization<_Traits, char_traits>{})); + return static_cast( + _Traits_find_first_of<_Traits>(_Mypair._Myval2._Myptr(), _Mypair._Myval2._Mysize, _Off, _Ptr, _Count)); } _NODISCARD _CONSTEXPR20 size_type find_first_of( _In_z_ const _Elem* const _Ptr, const size_type _Off = 0) const noexcept /* strengthened */ { // look for one of [_Ptr, ) at or after _Off - return static_cast(_Traits_find_first_of<_Traits>(_Mypair._Myval2._Myptr(), _Mypair._Myval2._Mysize, - _Off, _Ptr, _Traits::length(_Ptr), _Is_specialization<_Traits, char_traits>{})); + return static_cast(_Traits_find_first_of<_Traits>( + _Mypair._Myval2._Myptr(), _Mypair._Myval2._Mysize, _Off, _Ptr, _Traits::length(_Ptr))); } _NODISCARD _CONSTEXPR20 size_type find_first_of(const _Elem _Ch, const size_type _Off = 0) const noexcept { @@ -4518,7 +4504,7 @@ private: return _Max; } - return (_STD max) (_Masked, _Old + _Old / 2); + return (_STD max)(_Masked, _Old + _Old / 2); } _NODISCARD _CONSTEXPR20 size_type _Calculate_growth(const size_type _Requested) const noexcept {