Skip to content

Fix #186. #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/dfa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,19 @@ impl<'a> Fsm<'a> {
self.last_match_si = next_si;
prev_si = next_si;

// This permits short-circuiting when matching a regex set.
// In particular, if this DFA state contains only match states,
// then it's impossible to extend the set of matches since
// match states are final. Therefore, we can quit.
if self.prog.matches.len() > 1 {
let state = self.state(next_si);
let just_matches = state.insts.iter()
.all(|&ip| self.prog[ip as usize].is_match());
if just_matches {
return result;
}
}

// Another inner loop! If the DFA stays in this particular
// match state, then we can rip through all of the input
// very quickly, and only recording the match location once
Expand Down
10 changes: 10 additions & 0 deletions src/prog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ pub enum Inst {
Bytes(InstBytes),
}

impl Inst {
/// Returns true if and only if this is a match instruction.
pub fn is_match(&self) -> bool {
match *self {
Inst::Match(_) => true,
_ => false,
}
}
}

/// Representation of the Save instruction.
#[derive(Clone, Debug)]
pub struct InstSave {
Expand Down