Commit 661bf53
committed
literal: fix reverse suffix optimization
This commit fixes a bug where the reverse suffix literal optimization
wasn't quite right. It was too eagerly skipping past parts of the input
without verifying that there was no match. We fix this by being a bit more
careful with what we're searching by keeping track of the starting position
of the last literal matched. Subsequent literal searches then start
immediately after the last one.
This is necessary in particular when the suffix literal can have
overlapping matches. e.g., searching `000` in `0000` can match at either
positions 0 or 1, but searching `abc` in `abcd` can only match as position
0.
This was initially reported as a bug against ripgrep:
BurntSushi/ripgrep#12031 parent 60d087a commit 661bf53
2 files changed
+12
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
745 | 745 | | |
746 | 746 | | |
747 | 747 | | |
| 748 | + | |
748 | 749 | | |
749 | | - | |
750 | | - | |
| 750 | + | |
751 | 751 | | |
752 | | - | |
| 752 | + | |
753 | 753 | | |
| 754 | + | |
754 | 755 | | |
755 | 756 | | |
756 | 757 | | |
| |||
760 | 761 | | |
761 | 762 | | |
762 | 763 | | |
763 | | - | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
764 | 769 | | |
765 | 770 | | |
766 | 771 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
85 | 88 | | |
86 | 89 | | |
87 | 90 | | |
| |||
0 commit comments