<regex>
: Cache bitmasks of negated character classes during matching
#5487
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_Skip
and_Do_class
in sync, and the logic in_Skip
is by far not as well-tested as_Do_class
.To fuse the duplicated logic, I changed
_Do_class
to 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_class
just returns the starting position.The current matcher position is now updated in
_Match_pat
after calling_Do_class
, while_Skip
just checks whether_Do_class
returns the starting position or not.