Skip to content

Commit 9850538

Browse files
committed
impl: switch to aho-corasick 1.0
This is a transitory commit that will need to be updated once aho-corasick 1.0 is actually released. Its purpose is to make it so the regex crate, the "old" regex crate and regex-automata all agree on the same version of aho-corasick to use while in development.
1 parent 0711b7d commit 9850538

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ pattern = []
107107

108108
# For very fast prefix literal matching.
109109
[dependencies.aho-corasick]
110-
version = "0.7.18"
110+
version = "0.7.20"
111111
optional = true
112+
git = "https://github.com/BurntSushi/aho-corasick"
112113

113114
# For skipping along search text quickly when a leading byte is known.
114115
[dependencies.memchr]

src/exec.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::panic::AssertUnwindSafe;
44
use std::sync::Arc;
55

66
#[cfg(feature = "perf-literal")]
7-
use aho_corasick::{AhoCorasick, AhoCorasickBuilder, MatchKind};
7+
use aho_corasick::{AhoCorasick, MatchKind};
88
use regex_syntax::hir::literal;
99
use regex_syntax::hir::{Hir, Look};
1010
use regex_syntax::ParserBuilder;
@@ -101,7 +101,7 @@ struct ExecReadOnly {
101101
/// if we were to exhaust the ID space, we probably would have long
102102
/// surpassed the compilation size limit.
103103
#[cfg(feature = "perf-literal")]
104-
ac: Option<AhoCorasick<u32>>,
104+
ac: Option<AhoCorasick>,
105105
/// match_type encodes as much upfront knowledge about how we're going to
106106
/// execute a search as possible.
107107
match_type: MatchType,
@@ -395,7 +395,7 @@ impl ExecBuilder {
395395
}
396396

397397
#[cfg(feature = "perf-literal")]
398-
fn build_aho_corasick(&self, parsed: &Parsed) -> Option<AhoCorasick<u32>> {
398+
fn build_aho_corasick(&self, parsed: &Parsed) -> Option<AhoCorasick> {
399399
if parsed.exprs.len() != 1 {
400400
return None;
401401
}
@@ -409,10 +409,9 @@ impl ExecBuilder {
409409
return None;
410410
}
411411
Some(
412-
AhoCorasickBuilder::new()
412+
AhoCorasick::builder()
413413
.match_kind(MatchKind::LeftmostFirst)
414-
.auto_configure(&lits)
415-
.build_with_size::<u32, _, _>(&lits)
414+
.build(&lits)
416415
// This should never happen because we'd long exceed the
417416
// compilation limit for regexes first.
418417
.expect("AC automaton too big"),

src/literal/imp.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::mem;
22

3-
use aho_corasick::{self, packed, AhoCorasick, AhoCorasickBuilder};
3+
use aho_corasick::{self, packed, AhoCorasick};
44
use memchr::{memchr, memchr2, memchr3, memmem};
55
use regex_syntax::hir::literal::{Literal, Seq};
66

@@ -26,7 +26,7 @@ enum Matcher {
2626
/// A single substring, using vector accelerated routines when available.
2727
Memmem(Memmem),
2828
/// An Aho-Corasick automaton.
29-
AC { ac: AhoCorasick<u32>, lits: Vec<Literal> },
29+
AC { ac: AhoCorasick, lits: Vec<Literal> },
3030
/// A packed multiple substring searcher, using SIMD.
3131
///
3232
/// Note that Aho-Corasick will actually use this packed searcher
@@ -149,7 +149,7 @@ impl LiteralSearcher {
149149
Empty => 0,
150150
Bytes(ref sset) => sset.dense.len(),
151151
Memmem(_) => 1,
152-
AC { ref ac, .. } => ac.pattern_count(),
152+
AC { ref ac, .. } => ac.patterns_len(),
153153
Packed { ref lits, .. } => lits.len(),
154154
}
155155
}
@@ -161,8 +161,8 @@ impl LiteralSearcher {
161161
Empty => 0,
162162
Bytes(ref sset) => sset.approximate_size(),
163163
Memmem(ref single) => single.approximate_size(),
164-
AC { ref ac, .. } => ac.heap_bytes(),
165-
Packed { ref s, .. } => s.heap_bytes(),
164+
AC { ref ac, .. } => ac.memory_usage(),
165+
Packed { ref s, .. } => s.memory_usage(),
166166
}
167167
}
168168
}
@@ -212,10 +212,10 @@ impl Matcher {
212212
return Matcher::Packed { s, lits: lits.to_owned() };
213213
}
214214
}
215-
let ac = AhoCorasickBuilder::new()
215+
let ac = AhoCorasick::builder()
216216
.match_kind(aho_corasick::MatchKind::LeftmostFirst)
217-
.dfa(true)
218-
.build_with_size::<u32, _, _>(&pats)
217+
.kind(aho_corasick::AhoCorasickKind::DFA)
218+
.build(&pats)
219219
.unwrap();
220220
Matcher::AC { ac, lits: lits.to_owned() }
221221
}

0 commit comments

Comments
 (0)