Avoid unnecessary ToLower calls in RegexCompiler generated code#35185
Avoid unnecessary ToLower calls in RegexCompiler generated code#35185stephentoub merged 3 commits intodotnet:masterfrom
Conversation
|
Tagging subscribers to this area: @eerhardt |
|
The logic in the PR seems sound, but it's not immediately obvious to me how it improved this benchmark. In the |
...libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs
Outdated
Show resolved
Hide resolved
That With the expression By default, This is why I was asking offline (thanks, btw) about what could lowercase to |
tarekgh
left a comment
There was a problem hiding this comment.
I am fine with the current change. will be fine too if we do the check on the control characters only as this was the case we were trying to fix in the first place.
We can skip calling ToLower{Invariant} if the only character that could possibly lower-case to the character we're comparing against is that character itself. This then also lets us employ optimizations like using IndexOf when searching for `\n` as part of expressions like `.*`.
9e57865 to
44b58d3
Compare
When
RegexOptions.IgnoreCaseis used, we can skip calling ToLower{Invariant} if the only character that could possibly lower-case to the character we're comparing against is that character itself. This then also lets us employ optimizations like using IndexOf when searching for\nas part of expressions like.*.cc: @GrabYourPitchforks, @tarekgh, @eerhardt, @pgovind