tricks are employed to make it fast. Tread carefully.
N.B. While this implementation is heavily commented, Russ Cox's series of
-articles on regexes is strongly recommended: https://swtch.com/~rsc/regexp/
+articles on regexes is strongly recommended: <https://swtch.com/~rsc/regexp/>
(As is the DFA implementation in RE2, which heavily influenced this
implementation.)
*/
let mut cache = cache.borrow_mut();
let cache = &mut cache.dfa;
let mut dfa = Fsm {
- prog: prog,
+ prog,
start: 0, // filled in below
- at: at,
- quit_after_match: quit_after_match,
+ at,
+ quit_after_match,
last_match_si: STATE_UNKNOWN,
last_cache_flush: at,
cache: &mut cache.inner,
let mut cache = cache.borrow_mut();
let cache = &mut cache.dfa_reverse;
let mut dfa = Fsm {
- prog: prog,
+ prog,
start: 0, // filled in below
- at: at,
- quit_after_match: quit_after_match,
+ at,
+ quit_after_match,
last_match_si: STATE_UNKNOWN,
last_cache_flush: at,
cache: &mut cache.inner,
let mut cache = cache.borrow_mut();
let cache = &mut cache.dfa;
let mut dfa = Fsm {
- prog: prog,
+ prog,
start: 0, // filled in below
- at: at,
+ at,
quit_after_match: false,
last_match_si: STATE_UNKNOWN,
last_cache_flush: at,
impl StateMap {
fn new(num_byte_classes: usize) -> StateMap {
- StateMap {
- map: HashMap::new(),
- states: vec![],
- num_byte_classes: num_byte_classes,
- }
+ StateMap { map: HashMap::new(), states: vec![], num_byte_classes }
}
fn len(&self) -> usize {
/// The number of byte classes corresponds to the stride. Every state will
/// have `num_byte_classes` slots for transitions.
fn new(num_byte_classes: usize) -> Transitions {
- Transitions { table: vec![], num_byte_classes: num_byte_classes }
+ Transitions { table: vec![], num_byte_classes }
}
/// Returns the total number of states currently in this table.
impl StateFlags {
fn is_match(&self) -> bool {
- self.0 & 0b0000000_1 > 0
+ self.0 & 0b0000_0001 > 0
}
fn set_match(&mut self) {
- self.0 |= 0b0000000_1;
+ self.0 |= 0b0000_0001;
}
fn is_word(&self) -> bool {
- self.0 & 0b000000_1_0 > 0
+ self.0 & 0b0000_0010 > 0
}
fn set_word(&mut self) {
- self.0 |= 0b000000_1_0;
+ self.0 |= 0b0000_0010;
}
fn has_empty(&self) -> bool {
- self.0 & 0b00000_1_00 > 0
+ self.0 & 0b0000_0100 > 0
}
fn set_empty(&mut self) {
- self.0 |= 0b00000_1_00;
+ self.0 |= 0b0000_0100;
}
}