Optimize newline handling for RegexOptions.Multiline#34566
Merged
stephentoub merged 2 commits intodotnet:masterfrom Apr 9, 2020
Merged
Optimize newline handling for RegexOptions.Multiline#34566stephentoub merged 2 commits intodotnet:masterfrom
stephentoub merged 2 commits intodotnet:masterfrom
Conversation
eerhardt
reviewed
Apr 6, 2020
...libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs
Outdated
Show resolved
Hide resolved
eerhardt
reviewed
Apr 6, 2020
...libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs
Outdated
Show resolved
Hide resolved
eerhardt
approved these changes
Apr 6, 2020
Member
eerhardt
left a comment
There was a problem hiding this comment.
Looks good to me. Nice improvement!
Member
|
Another case to handle if @jzabroski still plans to revive dotnet/corefx#41195 edit: I meant #1449 |
Contributor
|
@danmosemsft I do plan to. Just got trapped under mountain of COVID-19 DR planning work. I expect to give it the old college try in about 2 weeks. Thanks for thinking of me and tagging me. |
Member
|
Sure @jzabroski.. we will get there eventually! |
We previously didn't do any special handling of beginning-of-line anchors (^ when RegexOptions.Multiline is specified). This PR adds special handling for the anchor so that FindFirstChar will jump to the next newline as part of its processing. As part of this, I also cleaned up some of the anchor handling code. The RegexPrefixAnalyzer only ever returns a single anchor, but the rest of the code was written such that it was expecting multiple anchors.
Also factor out a few lines of duplication.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We previously didn't do any special handling of beginning-of-line anchors (
^whenRegexOptions.Multilineis specified). This PR adds special handling for the anchor so thatFindFirstCharwill jump to the next newline as part of its processing.As part of this, I also cleaned up some of the anchor handling code. The
RegexPrefixAnalyzeronly ever returns a single anchor, but the rest of the code was written such that it was expecting multiple anchors.Example:
Finding all lines in Romeo and Juliet that contain the word "love":
Contributes to #1349
cc: @pgovind, @eerhardt, @ViktorHofer, @danmosemsft