pub struct ResolverContext { /* private fields */ }Expand description
Per-call cache mapping raw pointer of each Pattern in the selector
tree to its CompiledPattern. Built once at entry; lookup is O(1)
hash.
§Cache reuse across calls
Build a single ResolverContext outside a retry loop and pass it to
resolve_selector_compiled / resolve_selector_all_compiled on
every iteration to skip the per-call regex compile prepass. The
regex hit case drops from ~9.5 µs/iter to ~260 ns/iter on a 15-node
tree (see BUDGETS.md). The convenience
wrappers resolve_selector / resolve_selector_all keep the
per-call construction for one-shot callers.
§Safety
*const Pattern is used only as a HashMap key — never dereferenced.
The borrowed Selector passed to ResolverContext::new must
outlive every subsequent resolve_selector_compiled call that uses
this context. Pattern addresses stay stable for the lifetime of the
outer &Selector borrow. Passing a context built from a different
Selector than the one being resolved is a runtime contract
violation (cache misses degrade to silent None from ctx.pattern).
Implementations§
Source§impl ResolverContext
impl ResolverContext
Sourcepub fn new(selector: &Selector) -> Option<Self>
pub fn new(selector: &Selector) -> Option<Self>
Build a context by walking the selector tree once and pre-compiling
every embedded Pattern. Returns None if any regex pattern
fails to compile (matches the silent-None semantic of
resolve_selector).
Sourcepub fn pattern(&self, p: &Pattern) -> Option<&CompiledPattern>
pub fn pattern(&self, p: &Pattern) -> Option<&CompiledPattern>
O(1) cache lookup. Returns None if p was not seen during the
build prepass — typically means p belongs to a different
selector tree than the one passed to ResolverContext::new.