Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call CRT wmemcmp/wmemchr when possible in char_traits for better performance #4873

Merged
merged 6 commits into from
Aug 8, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions stl/inc/__msvc_string_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,15 @@ struct _WChar_traits : private _Char_traits<_Elem, unsigned short> {
// compare [_First1, _First1 + _Count) with [_First2, ...)
#if _HAS_CXX17
if constexpr (is_same_v<_Elem, wchar_t>) {
#if _HAS_CXX20
if (_STD _Is_constant_evaluated()) {
mcfi marked this conversation as resolved.
Show resolved Hide resolved
return __builtin_wmemcmp(_First1, _First2, _Count);
mcfi marked this conversation as resolved.
Show resolved Hide resolved
} else {
return _CSTD wmemcmp(_First1, _First2, _Count);
}
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
return __builtin_wmemcmp(_First1, _First2, _Count);
#endif // ^^^ !_HAS_CXX20 ^^^
} else {
return _Primary_char_traits::compare(_First1, _First2, _Count);
}
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -249,7 +257,15 @@ struct _WChar_traits : private _Char_traits<_Elem, unsigned short> {
// look for _Ch in [_First, _First + _Count)
#if _HAS_CXX17
if constexpr (is_same_v<_Elem, wchar_t>) {
#if _HAS_CXX20
if (_STD _Is_constant_evaluated()) {
return __builtin_wmemchr(_First, _Ch, _Count);
} else {
return _CSTD wmemchr(_First, _Ch, _Count);
}
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
return __builtin_wmemchr(_First, _Ch, _Count);
#endif // ^^^ !_HAS_CXX20 ^^^
} else {
return _Primary_char_traits::find(_First, _Count, _Ch);
}
Expand Down
Loading