Skip to content

Commit ddc7188

Browse files
committed
literals: disable tuned boyer moore
There is a bug in the implementation and it's not clear how to fix it. A unit test has been added (marked to fail) that exposes the bug. For more discussion, see: #446
1 parent 608c191 commit ddc7188

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

Diff for: src/literals.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::cmp;
1211
use std::mem;
1312

1413
use aho_corasick::{Automaton, AcAutomaton, FullAcAutomaton};
@@ -681,7 +680,13 @@ impl BoyerMooreSearch {
681680
/// to beat the asm deep magic that is memchr. Unfortunately,
682681
/// I had trouble proving a useful turnover point. Hopefully,
683682
/// we can find one in the future.
684-
fn should_use(pattern: &[u8]) -> bool {
683+
fn should_use(_pattern: &[u8]) -> bool {
684+
// TBM is disabled until the bm_backstop_boundary unit test can pass
685+
// and we're more confident that the implementation is correct.
686+
//
687+
// See: https://github.com/rust-lang/regex/issues/446
688+
false
689+
/*
685690
// The minimum pattern length required to use TBM.
686691
const MIN_LEN: usize = 9;
687692
// The minimum frequency rank (lower is rarer) that every byte in the
@@ -709,6 +714,7 @@ impl BoyerMooreSearch {
709714
pattern.len() > MIN_LEN
710715
// all the bytes must be more common than the cutoff.
711716
&& pattern.iter().all(|c| freq_rank(*c) >= cutoff)
717+
*/
712718
}
713719

714720
/// Check to see if there is a match at the given position
@@ -939,6 +945,22 @@ mod tests {
939945
assert_eq!(needle_start, searcher.find(haystack.as_slice()).unwrap());
940946
}
941947

948+
#[test]
949+
#[should_panic]
950+
fn bm_backstop_boundary() {
951+
let haystack = b"\
952+
// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
953+
e_data.clone_created(entity_id, entity_to_add.entity_id);
954+
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
955+
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
956+
".to_vec();
957+
let needle = b"clone_created".to_vec();
958+
959+
let searcher = BoyerMooreSearch::new(needle);
960+
let result = searcher.find(&haystack);
961+
assert_eq!(Some(43), result);
962+
}
963+
942964
#[test]
943965
fn bm_win_gnu_indexing_bug() {
944966
let haystack_raw = vec![

0 commit comments

Comments
 (0)