Skip to content

Commit 89ed3b1

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 b07281b commit 89ed3b1

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;
@@ -98,7 +98,7 @@ struct ExecReadOnly {
9898
/// if we were to exhaust the ID space, we probably would have long
9999
/// surpassed the compilation size limit.
100100
#[cfg(feature = "perf-literal")]
101-
ac: Option<AhoCorasick<u32>>,
101+
ac: Option<AhoCorasick>,
102102
/// match_type encodes as much upfront knowledge about how we're going to
103103
/// execute a search as possible.
104104
match_type: MatchType,
@@ -392,7 +392,7 @@ impl ExecBuilder {
392392
}
393393

394394
#[cfg(feature = "perf-literal")]
395-
fn build_aho_corasick(&self, parsed: &Parsed) -> Option<AhoCorasick<u32>> {
395+
fn build_aho_corasick(&self, parsed: &Parsed) -> Option<AhoCorasick> {
396396
if parsed.exprs.len() != 1 {
397397
return None;
398398
}
@@ -406,10 +406,9 @@ impl ExecBuilder {
406406
return None;
407407
}
408408
Some(
409-
AhoCorasickBuilder::new()
409+
AhoCorasick::builder()
410410
.match_kind(MatchKind::LeftmostFirst)
411-
.auto_configure(&lits)
412-
.build_with_size::<u32, _, _>(&lits)
411+
.build(&lits)
413412
// This should never happen because we'd long exceed the
414413
// compilation limit for regexes first.
415414
.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)