Skip to content

Commit

Permalink
literal: fix reverse suffix literal optimization again
Browse files Browse the repository at this point in the history
The position at which we start searching for the literal should begin
at the given starting position, not 0.
  • Loading branch information
BurntSushi committed Feb 27, 2019
1 parent 9fb112e commit edf45e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,13 +745,13 @@ impl<'c> ExecNoSync<'c> {
debug_assert!(lcs.len() >= 1);
let mut start = original_start;
let mut end = start;
let mut last_literal_match = 0;
let mut last_literal = start;
while end <= text.len() {
last_literal_match += match lcs.find(&text[last_literal_match..]) {
last_literal += match lcs.find(&text[last_literal..]) {
None => return Some(NoMatch(text.len())),
Some(i) => i,
};
end = last_literal_match + lcs.len();
end = last_literal + lcs.len();
match dfa::Fsm::reverse(
&self.ro.dfa_reverse,
self.cache,
Expand All @@ -760,10 +760,10 @@ impl<'c> ExecNoSync<'c> {
end - start,
) {
Match(0) | NoMatch(0) => return None,
Match(s) => return Some(Match((s + start, end))),
Match(i) => return Some(Match((start + i, end))),
NoMatch(i) => {
start = i;
last_literal_match += 1;
start += i;
last_literal += 1;
continue;
}
Quit => return Some(Quit),
Expand Down
4 changes: 3 additions & 1 deletion tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ ismatch!(strange_anchor_non_complete_prefix, r"a^{2}", "", false);
ismatch!(strange_anchor_non_complete_suffix, r"${2}a", "", false);

// See: https://github.com/BurntSushi/ripgrep/issues/1203
ismatch!(wat1, r"[0-4][0-4][0-4]000", "153.230000", true);
ismatch!(reverse_suffix1, r"[0-4][0-4][0-4]000", "153.230000", true);
ismatch!(reverse_suffix2, r"\d\d\d000", "153.230000\n", true);
matiter!(reverse_suffix3, r"\d\d\d000", "153.230000\n", (4, 10));

// See: https://github.com/rust-lang/regex/issues/334
mat!(captures_after_dfa_premature_end, r"a(b*(X|$))?", "abcbX",
Expand Down

0 comments on commit edf45e6

Please sign in to comment.