Skip to content

Commit 04e8c74

Browse files
committed
api: deprecate byte classes and premultiply options
These options aren't really carrying their weight. In a future release, aho-corasick will make both options enabled by default all the time with the impossibility of disabling them. The main reason for this is that these options require a quadrupling in the amount of code in this crate. While it's possible to see a performance hit when using byte classes, it should generally be very small. The improvement, if one exists, just doesn't see worth it. Please see #57 for more discussion. This is meant to mirror a similar decision occurring in regex-automata: BurntSushi/regex-automata#7.
1 parent c3136f1 commit 04e8c74

3 files changed

Lines changed: 23 additions & 13 deletions

File tree

‎aho-corasick-debug/main.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ impl Args {
122122
eprintln!("pattern read time: {:?}", read_time);
123123

124124
let start = Instant::now();
125+
// TODO: remove when byte classes and premultiply options are removed.
126+
#[allow(deprecated)]
125127
let ac = AhoCorasickBuilder::new()
126128
.match_kind(self.match_kind)
127129
.ascii_case_insensitive(self.ascii_casei)

‎src/ahocorasick.rs‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,18 +1005,6 @@ impl<S: StateID> AhoCorasick<S> {
10051005
///
10061006
/// let ac = AhoCorasickBuilder::new()
10071007
/// .dfa(true)
1008-
/// .byte_classes(false)
1009-
/// .build(&["foo", "bar", "baz"]);
1010-
/// assert_eq!(20_768, ac.heap_bytes());
1011-
///
1012-
/// let ac = AhoCorasickBuilder::new()
1013-
/// .dfa(true)
1014-
/// .byte_classes(true) // default
1015-
/// .build(&["foo", "bar", "baz"]);
1016-
/// assert_eq!(1_248, ac.heap_bytes());
1017-
///
1018-
/// let ac = AhoCorasickBuilder::new()
1019-
/// .dfa(true)
10201008
/// .ascii_case_insensitive(true)
10211009
/// .build(&["foo", "bar", "baz"]);
10221010
/// assert_eq!(1_248, ac.heap_bytes());
@@ -1681,7 +1669,7 @@ impl AhoCorasickBuilder {
16811669
// N.B. Using byte classes can actually be faster by improving
16821670
// locality, but this only really applies for multi-megabyte
16831671
// automata (i.e., automata that don't fit in your CPU's cache).
1684-
self.dfa(true).byte_classes(false);
1672+
self.dfa(true);
16851673
} else if patterns.len() <= 5000 {
16861674
self.dfa(true);
16871675
}
@@ -1928,6 +1916,10 @@ impl AhoCorasickBuilder {
19281916
/// overall performance.
19291917
///
19301918
/// This option is enabled by default.
1919+
#[deprecated(
1920+
since = "0.7.16",
1921+
note = "not carrying its weight, will be always enabled, see: https://github.com/BurntSushi/aho-corasick/issues/57"
1922+
)]
19311923
pub fn byte_classes(&mut self, yes: bool) -> &mut AhoCorasickBuilder {
19321924
self.dfa_builder.byte_classes(yes);
19331925
self
@@ -1956,6 +1948,10 @@ impl AhoCorasickBuilder {
19561948
/// non-premultiplied form only requires 8 bits.
19571949
///
19581950
/// This option is enabled by default.
1951+
#[deprecated(
1952+
since = "0.7.16",
1953+
note = "not carrying its weight, will be always enabled, see: https://github.com/BurntSushi/aho-corasick/issues/57"
1954+
)]
19591955
pub fn premultiply(&mut self, yes: bool) -> &mut AhoCorasickBuilder {
19601956
self.dfa_builder.premultiply(yes);
19611957
self

‎src/tests.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,8 @@ macro_rules! testcombo {
739739
$collection,
740740
$kind,
741741
|b: &mut AhoCorasickBuilder| {
742+
// TODO: remove tests when option is removed.
743+
#[allow(deprecated)]
742744
b.dfa(true).byte_classes(false);
743745
}
744746
);
@@ -747,6 +749,8 @@ macro_rules! testcombo {
747749
$collection,
748750
$kind,
749751
|b: &mut AhoCorasickBuilder| {
752+
// TODO: remove tests when option is removed.
753+
#[allow(deprecated)]
750754
b.dfa(true).premultiply(false);
751755
}
752756
);
@@ -755,6 +759,8 @@ macro_rules! testcombo {
755759
$collection,
756760
$kind,
757761
|b: &mut AhoCorasickBuilder| {
762+
// TODO: remove tests when options are removed.
763+
#[allow(deprecated)]
758764
b.dfa(true).byte_classes(false).premultiply(false);
759765
}
760766
);
@@ -830,6 +836,8 @@ testconfig!(
830836
AC_STANDARD_OVERLAPPING,
831837
Standard,
832838
|b: &mut AhoCorasickBuilder| {
839+
// TODO: remove tests when option is removed.
840+
#[allow(deprecated)]
833841
b.dfa(true).byte_classes(false);
834842
}
835843
);
@@ -839,6 +847,8 @@ testconfig!(
839847
AC_STANDARD_OVERLAPPING,
840848
Standard,
841849
|b: &mut AhoCorasickBuilder| {
850+
// TODO: remove tests when option is removed.
851+
#[allow(deprecated)]
842852
b.dfa(true).premultiply(false);
843853
}
844854
);
@@ -848,6 +858,8 @@ testconfig!(
848858
AC_STANDARD_OVERLAPPING,
849859
Standard,
850860
|b: &mut AhoCorasickBuilder| {
861+
// TODO: remove tests when options are removed.
862+
#[allow(deprecated)]
851863
b.dfa(true).byte_classes(false).premultiply(false);
852864
}
853865
);

0 commit comments

Comments
 (0)