Returns true iff the given regex and input should be executed by this engine with reasonable memory usage.
(num_insts: usize, text_len: usize)
| 39 | /// Returns true iff the given regex and input should be executed by this |
| 40 | /// engine with reasonable memory usage. |
| 41 | pub fn should_exec(num_insts: usize, text_len: usize) -> bool { |
| 42 | // Total memory usage in bytes is determined by: |
| 43 | // |
| 44 | // ((len(insts) * (len(input) + 1) + bits - 1) / bits) * (size_of(u32)) |
| 45 | // |
| 46 | // The actual limit picked is pretty much a heuristic. |
| 47 | // See: https://github.com/rust-lang/regex/issues/215 |
| 48 | let size = ((num_insts * (text_len + 1) + BIT_SIZE - 1) / BIT_SIZE) * 4; |
| 49 | size <= MAX_SIZE_BYTES |
| 50 | } |
| 51 | |
| 52 | /// A backtracking matching engine. |
| 53 | #[derive(Debug)] |