<regex>
: Cache bitmasks of negated character classes during matching by muellerj2 · Pull Request #5487 · microsoft/STL (original) (raw)
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.