<regex>: Speed up skip optimization for default regex_traits in collate mode by muellerj2 · Pull Request #5672 · microsoft/STL (original) (raw)
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 |