<regex>: Cache bitmasks of negated character classes during matching#5487
Merged
StephanTLavavej merged 1 commit intomicrosoft:mainfrom May 17, 2025
Merged
Conversation
StephanTLavavej
approved these changes
May 15, 2025
Member
|
This is great, thank you! 😻 |
Member
|
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Member
💵 0️⃣ 1️⃣ 🤿 |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow-up to #5403: Since the matcher class just got renamed, we can add some member variables to cache the bitmasks for negated character classes when such negated character classes appear in the regex. This way, we can avoid the class lookup whenever we encounter such character classes during matching.
I also removed the duplicated class-matching logic in
_Skip: It was annoying to keep_Skipand_Do_classin sync, and the logic in_Skipis by far not as well-tested as_Do_class.To fuse the duplicated logic, I changed
_Do_classto no longer modify the matcher's current position. Instead, it now takes a position starting from which the class should match and returns the position just after the sequence actually matched by the class. (Note that this can be more than one character because of collating elements.) If the character class doesn't match,_Do_classjust returns the starting position.The current matcher position is now updated in
_Match_patafter calling_Do_class, while_Skipjust checks whether_Do_classreturns the starting position or not.