diff --git a/lib/src/compiler/mod.rs b/lib/src/compiler/mod.rs index b29114a3a..5fc3abd3c 100644 --- a/lib/src/compiler/mod.rs +++ b/lib/src/compiler/mod.rs @@ -2149,8 +2149,8 @@ impl<'a> Compiler<'a> { MinMaxResult::NoElements => true, // Only one atom shorter than 2 bytes, slow pattern. MinMaxResult::OneElement(len) if len < 2 => true, - // More than one atom, but all shorter than 2 bytes. - MinMaxResult::MinMax(_, max) if max < 2 => true, + // More than one atom, at least one is shorter than 2 bytes. + MinMaxResult::MinMax(min, _) if min < 2 => true, // More than 2700 atoms, all with exactly 2 bytes. // Why 2700?. The larger the number of atoms the higher the // odds of finding one of them in the data, which slows down diff --git a/lib/src/compiler/tests/testdata/warnings/23.in b/lib/src/compiler/tests/testdata/warnings/23.in index 9ce1726bd..4037e2418 100644 --- a/lib/src/compiler/tests/testdata/warnings/23.in +++ b/lib/src/compiler/tests/testdata/warnings/23.in @@ -1,6 +1,13 @@ -rule test { +rule test_1 { strings: $a = {00 [1-10] 01} - condition: + condition: $a +} + +rule test_2 { + strings: + $a = /a.*/ + condition: + $a } \ No newline at end of file diff --git a/lib/src/compiler/tests/testdata/warnings/23.out b/lib/src/compiler/tests/testdata/warnings/23.out index 7de9bee7b..9a30901e4 100644 --- a/lib/src/compiler/tests/testdata/warnings/23.out +++ b/lib/src/compiler/tests/testdata/warnings/23.out @@ -4,3 +4,9 @@ warning[slow_pattern]: slow pattern 3 | $a = {00 [1-10] 01} | ------------------ this pattern may slow down the scan | +warning[slow_pattern]: slow pattern + --> line:10:4 + | +10 | $a = /a.*/ + | ---------- this pattern may slow down the scan + | diff --git a/py/src/lib.rs b/py/src/lib.rs index d49966bfb..7ad1dc9ba 100644 --- a/py/src/lib.rs +++ b/py/src/lib.rs @@ -59,12 +59,8 @@ impl Compiler { error_on_slow_pattern: bool, ) -> yrx::Compiler<'static> { let mut compiler = yrx::Compiler::new(); - if relaxed_re_syntax { - compiler.relaxed_re_syntax(true); - } - if error_on_slow_pattern { - compiler.error_on_slow_pattern(true); - } + compiler.relaxed_re_syntax(relaxed_re_syntax); + compiler.error_on_slow_pattern(error_on_slow_pattern); compiler } }