pub struct Matcher { /* private fields */ }Expand description
The scratch a match needs, kept across calls.
ARGREP runs a predicate per visited element, so the three vectors are
allocated once for the command rather than once per element. A Matcher can
be used with any Regex; it grows to the largest one it has seen.
Implementations§
Source§impl Matcher
impl Matcher
Sourcepub fn reserve(&mut self, re: &Regex)
pub fn reserve(&mut self, re: &Regex)
Grows the scratch to what re will need, so that matching never does.
A state is added at most once per step, so none of the four vectors can
go past the program size. Doing the growth here means the caller can put
every allocation ARGREP makes in the part of the command that reads the
arguments, and the walk over the elements allocates nothing at all.
Sourcepub fn is_match(&mut self, re: &Regex, hay: &[u8]) -> bool
pub fn is_match(&mut self, re: &Regex, hay: &[u8]) -> bool
Whether re matches anywhere in hay.
Unanchored, which is what regexec without an anchor does and what
ARGREP RE means: the pattern has to match some run of bytes, not the
whole element.
The walk is a Thompson simulation. Every state that could be live at a position is live at once, so a byte is looked at exactly once and the cost is the subject length times the program size in the worst case, with no backtracking and therefore no pattern that makes it exponential.