Skip to content

Conversation

muellerj2
Copy link
Contributor

In the default std::regex_traits<char> and std::regex_traits<wchar_t> implementation, the translate() function just returns its argument unchanged (see [re.traits]/4). This means that the call to this function can be skipped for these traits classes.

This PR implements this change, and as a consequence, the skip optimization now engages the vectorized std::search implementation in collate mode as well.

The tests added by #5553 already check correct handling of translate() in the skip optimization for user-provided regex traits, so this PR just adds a short variant of this test for default std::regex and std::wregex.

Benchmark (only relevant lines):

name before after speedup
bm_lorem_search/"bibe"/2 2825 ns 2915 ns 0.97
bm_lorem_search/"bibe"/3 5625 ns 5580 ns 1.01
bm_lorem_search/"bibe"/4 10986 ns 11160 ns 0.98
bm_lorem_search/"bibe".collate/2 15346 ns 2915 ns 5.26
bm_lorem_search/"bibe".collate/3 30482 ns 5625 ns 5.42
bm_lorem_search/"bibe".collate/4 61384 ns 11718 ns 5.24

@muellerj2 muellerj2 requested a review from a team as a code owner August 10, 2025 13:39
@github-project-automation github-project-automation bot moved this to Initial Review in STL Code Reviews Aug 10, 2025
@StephanTLavavej StephanTLavavej added performance Must go faster regex meow is a substring of homeowner labels Aug 10, 2025
@StephanTLavavej StephanTLavavej self-assigned this Aug 10, 2025
@StephanTLavavej StephanTLavavej removed their assignment Aug 11, 2025
@StephanTLavavej StephanTLavavej moved this from Initial Review to Ready To Merge in STL Code Reviews Aug 11, 2025
@StephanTLavavej StephanTLavavej moved this from Ready To Merge to Merging in STL Code Reviews Aug 15, 2025
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit 8aa8f97 into microsoft:main Aug 16, 2025
39 checks passed
@github-project-automation github-project-automation bot moved this from Merging to Done in STL Code Reviews Aug 16, 2025
@StephanTLavavej
Copy link
Member

🚀 🚀 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster regex meow is a substring of homeowner
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants