pub struct Grep<'a> { /* private fields */ }Expand description
What one ARGREP was asked to look for.
Built once per command and then asked about every element the walk visits, which is why the compiled regexes and the matcher’s scratch space live here rather than being made per element.
§This one allocates
Every other command path here is allocation free, and ARGREP cannot be:
compiling a regular expression means building a program, and the plan holds
up to two hundred and fifty predicates. Redis allocates in the same two
places for the same reasons. The allocations are wrapped in
yo_alloc::allow and they all happen while the command is being read, so
the walk itself is still allocation free however many elements it visits.
Implementations§
Source§impl<'a> Grep<'a>
impl<'a> Grep<'a>
Sourcepub fn new() -> Grep<'a>
pub fn new() -> Grep<'a>
An empty plan, which is not a usable one until it has been told what to
look for and then Grep::compiled.
Sourcepub fn push(&mut self, test: Test, pattern: &'a [u8]) -> Result<()>
pub fn push(&mut self, test: Test, pattern: &'a [u8]) -> Result<()>
Adds one predicate in the order it was written.
§Errors
Code::Invalid once there are GREP_MAX_PREDICATES of them, or for
an RE pattern longer than GREP_MAX_RE_LEN. Both are checked here
rather than at the end because Redis checks them as it reads, so a
command that is wrong in two ways reports whichever comes first.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
How many predicates the plan carries, since none at all is a syntax error and the caller is the one that says so.
Sourcepub fn compile(&mut self, all: bool, nocase: bool) -> Result<()>
pub fn compile(&mut self, all: bool, nocase: bool) -> Result<()>
Settles the two global options and compiles the regular expressions.
The compile is deliberately the last thing that happens while the command
is being read, because NOCASE is a global option that may come after
the pattern it applies to.
§Errors
Code::Invalid with the sentence Redis uses for an empty pattern, a
pattern that will not compile, or a pattern using a backreference.