Lines Matching defs:cache

15    during a search. When a new state is computed, it is stored in a cache so
20 2. If the cache gets too big, we wipe it and continue matching.
25 simulation, in large part because the cache becomes useless. If the cache
77 /// A reusable cache of DFA states.
79 /// This cache is reused between multiple invocations of the same regex
84 /// Group persistent DFA related cache state together. The sparse sets
103 /// A cache of pre-compiled DFA states, keyed by the set of NFA states
140 /// The total number of times this cache has been flushed by the DFA
143 /// The total heap size of the DFA's cache. We use this to determine when
144 /// we should flush the cache.
177 /// when the cache is wiped.
192 /// The input position of the last cache flush. We use this to determine
193 /// if we're thrashing in the cache too often. If so, the DFA quits so
197 cache: &'a mut CacheInner,
203 /// DFA runs too slowly because the cache size is too small. In that case, it
413 /// Create new empty cache for the DFA engine.
418 let mut cache = Cache {
431 cache.inner.reset_size();
432 cache
437 /// Resets the cache size to account for fixed costs, such as the program
449 cache: &ProgramCache,
454 let mut cache = cache.borrow_mut();
455 let cache = &mut cache.dfa;
463 cache: &mut cache.inner,
467 match dfa.start_state(&mut cache.qcur, empty_flags, state_flags) {
473 dfa.exec_at(&mut cache.qcur, &mut cache.qnext, text)
479 cache: &ProgramCache,
484 let mut cache = cache.borrow_mut();
485 let cache = &mut cache.dfa_reverse;
493 cache: &mut cache.inner,
497 match dfa.start_state(&mut cache.qcur, empty_flags, state_flags) {
503 dfa.exec_at_reverse(&mut cache.qcur, &mut cache.qnext, text)
509 cache: &ProgramCache,
515 let mut cache = cache.borrow_mut();
516 let cache = &mut cache.dfa;
524 cache: &mut cache.inner,
528 match dfa.start_state(&mut cache.qcur, empty_flags, state_flags) {
534 let result = dfa.exec_at(&mut cache.qcur, &mut cache.qnext, text);
706 // cache too much.
879 self.cache.trans.next_unchecked(si, cls as usize)
988 let cache = if b.is_eof() && self.prog.matches.len() > 1 {
994 // And don't cache this state because it's totally bunk.
1001 // next DFA state, so try to find it in the cache, and if it doesn't
1002 // exist, cache it.
1004 // N.B. We pass `&mut si` here because the cache may clear itself if
1023 if cache {
1025 self.cache.trans.set_next(si, cls, next);
1064 self.cache.stack.push(ip);
1065 while let Some(mut ip) = self.cache.stack.pop() {
1120 self.cache.stack.push(inst.goto2 as InstPtr);
1139 /// If the cache is full, then it is wiped before caching a new state.
1142 /// to be preserved if the cache clears itself. (Start states are
1144 /// pointer to the index because if the cache is cleared, the state's
1163 // In the cache? Cool. Done.
1164 if let Some(si) = self.cache.compiled.get_ptr(&key) {
1167 // If the cache has gotten too big, wipe it.
1178 /// Produces a key suitable for describing a state in the DFA cache.
1202 // cache.
1205 mem::replace(&mut self.cache.insts_scratch_space, vec![]);
1240 self.cache.insts_scratch_space = insts;
1244 /// Clears the cache, but saves and restores current_state if it is not
1248 /// cache changes.
1250 /// This returns false if the cache is not cleared and the DFA should
1256 if self.cache.compiled.is_empty() {
1267 // The unwrap is OK because we just cleared the cache and
1276 /// Wipes the state cache, but saves and restores the current start state.
1278 /// This returns false if the cache is not cleared and the DFA should
1284 // Additionally, we permit the cache to be flushed a few times before
1286 let nstates = self.cache.compiled.len();
1287 if self.cache.flush_count >= 3
1293 // Update statistics tracking cache flushes.
1295 self.cache.flush_count += 1;
1297 // OK, actually flush the cache.
1304 self.cache.reset_size();
1305 self.cache.trans.clear();
1306 self.cache.compiled.clear();
1307 for s in &mut self.cache.start_states {
1310 // The unwraps are OK because we just cleared the cache and therefore
1320 /// Restores the given state back into the cache, and returns a pointer
1325 if let Some(si) = self.cache.compiled.get_ptr(&state) {
1335 /// This tries to fetch the next state from the cache, but if that fails,
1353 match self.cache.trans.next(si, self.byte_class(b)) {
1362 /// then it is pulled from the cache. If the state hasn't been cached,
1373 // Compute an index into our cache of start states based on the set
1387 match self.cache.start_states[flagi] {
1402 self.cache.start_states[flagi] = sp;
1463 self.cache.compiled.get_state(si).unwrap()
1469 /// self.cache.trans. The transitions can be set with the returned
1476 // practice, the cache limit will prevent us from ever getting here,
1477 // but maybe callers will set the cache size to something ridiculous...
1478 let si = match self.cache.trans.add() {
1489 self.cache.trans.set_next(si, cls, STATE_QUIT);
1494 self.cache.size += self.cache.trans.state_heap_size()
1498 self.cache.compiled.insert(state, si);
1501 self.cache.compiled.len() == self.cache.trans.num_states()
1574 /// the DFA. It is used to determine whether the DFA's state cache needs to
1577 /// bad for memory use, so we bound it with a cache.)
1579 self.cache.size + self.prog.approximate_size()