MCPcopy Create free account
hub / github.com/davidblewett/rure-python / cached_state

Method cached_state

regex/src/dfa.rs:1165–1199  ·  view source on GitHub ↗

Find a previously computed state matching the given set of instructions and is_match bool. The given set of instructions should represent a single state in the NFA along with all states reachable without consuming any input. The is_match bool should be true if and only if the preceding DFA state contains an NFA matching state. The cached state produced here will then signify a match. (This enabl

(
        &mut self,
        q: &SparseSet,
        mut state_flags: StateFlags,
        current_state: Option<&mut StatePtr>,
    )

Source from the content-addressed store, hash-verified

1163 /// pointer to the index because if the cache is cleared, the state's
1164 /// location may change.
1165 fn cached_state(
1166 &mut self,
1167 q: &SparseSet,
1168 mut state_flags: StateFlags,
1169 current_state: Option<&mut StatePtr>,
1170 ) -> Option<StatePtr> {
1171 // If we couldn't come up with a non-empty key to represent this state,
1172 // then it is dead and can never lead to a match.
1173 //
1174 // Note that inst_flags represent the set of empty width assertions
1175 // in q. We use this as an optimization in exec_byte to determine when
1176 // we should follow epsilon transitions at the empty string preceding
1177 // the current byte.
1178 let key = match self.cached_state_key(q, &mut state_flags) {
1179 None => return Some(STATE_DEAD),
1180 Some(v) => v,
1181 };
1182 // In the cache? Cool. Done.
1183 if let Some(si) = self
1184 .cache
1185 .compiled
1186 .get_ptr(&key)
1187 {
1188 return Some(si);
1189 }
1190 // If the cache has gotten too big, wipe it.
1191 if self.approximate_size() > self.prog.dfa_size_limit
1192 && !self.clear_cache_and_save(current_state)
1193 {
1194 // Ooops. DFA is giving up.
1195 return None;
1196 }
1197 // Allocate room for our state and add it.
1198 self.add_state(key)
1199 }
1200
1201 /// Produces a key suitable for describing a state in the DFA cache.
1202 ///

Callers 2

exec_byteMethod · 0.80
start_stateMethod · 0.80

Calls 5

cached_state_keyMethod · 0.80
get_ptrMethod · 0.80
clear_cache_and_saveMethod · 0.80
add_stateMethod · 0.80
approximate_sizeMethod · 0.45

Tested by

no test coverage detected