Skip to content

Commit ab4a117

Browse files
authored
Improve RegexCompiler's ToLower perf (#35203)
* Pool LocalBuilders in RegexCompiler Currently GenerateGo/FindFirstChar create a few _tempLocal1, _tempLocal2, etc. LocalBuilders that various parts of the methods may use. The developer then need to keep track of which of these locals is currently being used such that we maximize the re-use of them while not accidentally overlapping their use. And the names end up being non-descriptive, so in some cases additional names are added for convenience. The primary purpose of the PR is cleanup. It adds a pool of LocalBuilders that lets them be rented just where they're needed, such that we only create locals when necessary, can give them appropriate names, etc. However, it also makes it a lot easier for helpers to create temporary locals (e.g. as was done in EmitMatchCharacterClass) which then makes it easier to add additional optimizations. * Avoid CultureInfo.TextInfo virtual calls in RegexCompiler To support RegexOptions.IgnoreCase, RegexCompiler ends up generating a call to `char.ToLower(c, _culture)` for every character compared. That `ToLower` call in turn needs to access `_culture.TextInfo`, and then call its `ToLower(char)` virtual method. We can instead get the `TextInfo` once and call its `ToLower` method directly, saving a virtual call on every character being compared. Note that we were already doing this (for .NET 5) in RegexInterpreter, but hadn't done it in RegexCompiler because of complications around locals management. The previous commit fixed that and made this possible. * Update src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs
1 parent 774daf4 commit ab4a117

File tree

1 file changed

+451
-443
lines changed
  • src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions

1 file changed

+451
-443
lines changed

0 commit comments

Comments
 (0)