Wipes the state cache, but saves and restores the current start state. This returns false if the cache is not cleared and the DFA should give up.
(&mut self)
| 1304 | /// This returns false if the cache is not cleared and the DFA should |
| 1305 | /// give up. |
| 1306 | fn clear_cache(&mut self) -> bool { |
| 1307 | // Bail out of the DFA if we're moving too "slowly." |
| 1308 | // A heuristic from RE2: assume the DFA is too slow if it is processing |
| 1309 | // 10 or fewer bytes per state. |
| 1310 | // Additionally, we permit the cache to be flushed a few times before |
| 1311 | // caling it quits. |
| 1312 | let nstates = self.cache.compiled.len(); |
| 1313 | if self.cache.flush_count >= 3 |
| 1314 | && self.at >= self.last_cache_flush |
| 1315 | && (self.at - self.last_cache_flush) <= 10 * nstates { |
| 1316 | return false; |
| 1317 | } |
| 1318 | // Update statistics tracking cache flushes. |
| 1319 | self.last_cache_flush = self.at; |
| 1320 | self.cache.flush_count += 1; |
| 1321 | |
| 1322 | // OK, actually flush the cache. |
| 1323 | let start = self.state(self.start & !STATE_START).clone(); |
| 1324 | let last_match = if self.last_match_si <= STATE_MAX { |
| 1325 | Some(self.state(self.last_match_si).clone()) |
| 1326 | } else { |
| 1327 | None |
| 1328 | }; |
| 1329 | self.cache.reset_size(); |
| 1330 | self.cache.trans.clear(); |
| 1331 | self.cache.compiled.clear(); |
| 1332 | for s in &mut self.cache.start_states { |
| 1333 | *s = STATE_UNKNOWN; |
| 1334 | } |
| 1335 | // The unwraps are OK because we just cleared the cache and therefore |
| 1336 | // know that the next state pointer won't exceed STATE_MAX. |
| 1337 | let start_ptr = self.restore_state(start).unwrap(); |
| 1338 | self.start = self.start_ptr(start_ptr); |
| 1339 | if let Some(last_match) = last_match { |
| 1340 | self.last_match_si = self.restore_state(last_match).unwrap(); |
| 1341 | } |
| 1342 | true |
| 1343 | } |
| 1344 | |
| 1345 | /// Restores the given state back into the cache, and returns a pointer |
| 1346 | /// to it. |
no test coverage detected