Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/ahocorasick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,10 +903,10 @@ impl AhoCorasick {
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
#[cfg(feature = "std")]
pub fn stream_find_iter<'a, R: std::io::Read>(
&'a self,
pub fn stream_find_iter<R: std::io::Read>(
&self,
rdr: R,
) -> StreamFindIter<'a, R> {
) -> StreamFindIter<'_, R> {
self.try_stream_find_iter(rdr)
.expect("AhoCorasick::try_stream_find_iter should not fail")
}
Expand Down Expand Up @@ -1674,10 +1674,10 @@ impl AhoCorasick {
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
#[cfg(feature = "std")]
pub fn try_stream_find_iter<'a, R: std::io::Read>(
&'a self,
pub fn try_stream_find_iter<R: std::io::Read>(
&self,
rdr: R,
) -> Result<StreamFindIter<'a, R>, MatchError> {
) -> Result<StreamFindIter<'_, R>, MatchError> {
enforce_anchored_consistency(self.start_kind, Anchored::No)?;
self.aut.try_stream_find_iter(rdr).map(StreamFindIter)
}
Expand Down
16 changes: 7 additions & 9 deletions src/automaton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,10 @@ pub unsafe trait Automaton: private::Sealed {
/// [`AhoCorasick::try_stream_find_iter`](crate::AhoCorasick::try_stream_find_iter)
/// for more documentation and examples.
#[cfg(feature = "std")]
fn try_stream_find_iter<'a, R: std::io::Read>(
&'a self,
fn try_stream_find_iter<R: std::io::Read>(
&self,
rdr: R,
) -> Result<StreamFindIter<'a, Self, R>, MatchError>
) -> Result<StreamFindIter<'_, Self, R>, MatchError>
where
Self: Sized,
{
Expand Down Expand Up @@ -1272,12 +1272,10 @@ pub(crate) fn try_find_fwd<A: Automaton + ?Sized>(
} else {
try_find_fwd_imp(aut, input, Some(pre), Anchored::No, false)
}
} else if earliest {
try_find_fwd_imp(aut, input, None, Anchored::No, true)
} else {
if earliest {
try_find_fwd_imp(aut, input, None, Anchored::No, true)
} else {
try_find_fwd_imp(aut, input, None, Anchored::No, false)
}
try_find_fwd_imp(aut, input, None, Anchored::No, false)
}
}

Expand Down Expand Up @@ -1585,7 +1583,7 @@ pub(crate) fn sparse_transitions<'a>(
) -> impl Iterator<Item = (u8, u8, StateID)> + 'a {
let mut cur: Option<(u8, u8, StateID)> = None;
core::iter::from_fn(move || {
while let Some((class, next)) = it.next() {
for (class, next) in it.by_ref() {
let (prev_start, prev_end, prev_next) = match cur {
Some(x) => x,
None => {
Expand Down
16 changes: 8 additions & 8 deletions src/dfa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ impl core::fmt::Debug for DFA {
)?;
}
}
write!(f, "\n")?;
writeln!(f)?;
if self.is_match(sid) {
write!(f, " matches: ")?;
for i in 0..self.match_len(sid) {
Expand All @@ -362,7 +362,7 @@ impl core::fmt::Debug for DFA {
let pid = self.match_pattern(sid, i);
write!(f, "{}", pid.as_usize())?;
}
write!(f, "\n")?;
writeln!(f)?;
}
}
writeln!(f, "match kind: {:?}", self.match_kind)?;
Expand Down Expand Up @@ -434,7 +434,7 @@ impl Builder {
) -> Result<DFA, BuildError> {
debug!("building DFA");
let byte_classes = if self.byte_classes {
nnfa.byte_classes().clone()
*nnfa.byte_classes()
} else {
ByteClasses::singletons()
};
Expand Down Expand Up @@ -494,7 +494,7 @@ impl Builder {
matches: vec![vec![]; num_match_states],
matches_memory_usage: 0,
pattern_lens: nnfa.pattern_lens_raw().to_vec(),
prefilter: nnfa.prefilter().map(|p| p.clone()),
prefilter: nnfa.prefilter().cloned(),
match_kind: nnfa.match_kind(),
state_len,
alphabet_len: byte_classes.alphabet_len(),
Expand Down Expand Up @@ -564,9 +564,9 @@ impl Builder {
&dfa.byte_classes,
|byte, class, mut oldnextsid| {
if oldnextsid == noncontiguous::NFA::FAIL {
if anchored.is_anchored() {
oldnextsid = noncontiguous::NFA::DEAD;
} else if state.fail() == noncontiguous::NFA::DEAD {
if anchored.is_anchored()
|| state.fail() == noncontiguous::NFA::DEAD
{
// This is a special case that avoids following
// DEAD transitions in a non-contiguous NFA.
// Following these transitions is pretty slow
Expand Down Expand Up @@ -701,7 +701,7 @@ impl Builder {
);
}
}
for i in 0..dfa.state_len {
for (i, _) in is_anchored.iter().enumerate().take(dfa.state_len) {
let sid = i << stride2;
if is_anchored[i] {
for next in dfa.trans[sid..][..stride].iter_mut() {
Expand Down
10 changes: 5 additions & 5 deletions src/nfa/contiguous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl core::fmt::Debug for NFA {
state.fail.as_usize()
)?;
state.fmt(f)?;
write!(f, "\n")?;
writeln!(f)?;
if self.is_match(sid) {
write!(f, " matches: ")?;
for i in 0..state.match_len {
Expand All @@ -352,7 +352,7 @@ impl core::fmt::Debug for NFA {
}
write!(f, "{}", pid.as_usize())?;
}
write!(f, "\n")?;
writeln!(f)?;
}
// The FAIL state doesn't actually have space for a state allocated
// for it, so we have to treat it as a special case. write below
Expand Down Expand Up @@ -821,7 +821,7 @@ impl<'a> State<'a> {

/// Return an iterator over every explicitly defined transition in this
/// state.
fn transitions<'b>(&'b self) -> impl Iterator<Item = (u8, StateID)> + 'b {
fn transitions(&self) -> impl Iterator<Item = (u8, StateID)> + '_ {
let mut i = 0;
core::iter::from_fn(move || match self.trans {
StateTrans::Sparse { classes, nexts } => {
Expand Down Expand Up @@ -940,7 +940,7 @@ impl Builder {
) -> Result<NFA, BuildError> {
debug!("building contiguous NFA");
let byte_classes = if self.byte_classes {
nnfa.byte_classes().clone()
*nnfa.byte_classes()
} else {
ByteClasses::singletons()
};
Expand All @@ -949,7 +949,7 @@ impl Builder {
repr: vec![],
pattern_lens: nnfa.pattern_lens_raw().to_vec(),
state_len: nnfa.states().len(),
prefilter: nnfa.prefilter().map(|p| p.clone()),
prefilter: nnfa.prefilter().cloned(),
match_kind: nnfa.match_kind(),
alphabet_len: byte_classes.alphabet_len(),
byte_classes,
Expand Down
4 changes: 2 additions & 2 deletions src/nfa/noncontiguous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ impl core::fmt::Debug for NFA {
}
}

write!(f, "\n")?;
writeln!(f)?;
if self.is_match(sid) {
write!(f, " matches: ")?;
for (i, pid) in self.iter_matches(sid).enumerate() {
Expand All @@ -1746,7 +1746,7 @@ impl core::fmt::Debug for NFA {
}
write!(f, "{}", pid.as_usize())?;
}
write!(f, "\n")?;
writeln!(f)?;
}
}
writeln!(f, "match kind: {:?}", self.match_kind)?;
Expand Down
2 changes: 1 addition & 1 deletion src/packed/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ impl<'s, 'h> Iterator for FindIter<'s, 'h> {
if self.span.start > self.span.end {
return None;
}
match self.searcher.find_in(&self.haystack, self.span) {
match self.searcher.find_in(self.haystack, self.span) {
None => None,
Some(m) => {
self.span.start = m.end();
Expand Down
4 changes: 2 additions & 2 deletions src/packed/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub(crate) struct Pattern<'a>(&'a [u8]);
impl<'a> fmt::Debug for Pattern<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Pattern")
.field("lit", &String::from_utf8_lossy(&self.0))
.field("lit", &String::from_utf8_lossy(self.0))
.finish()
}
}
Expand All @@ -224,7 +224,7 @@ impl<'p> Pattern<'p> {

/// Returns the bytes of this pattern.
pub(crate) fn bytes(&self) -> &[u8] {
&self.0
self.0
}

/// Returns the first `len` low nybbles from this pattern. If this pattern
Expand Down
7 changes: 1 addition & 6 deletions src/util/alphabet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,7 @@ impl<'a> Iterator for ByteClassElements<'a> {
type Item = u8;

fn next(&mut self) -> Option<u8> {
while let Some(byte) = self.bytes.next() {
if self.class == self.classes.get(byte) {
return Some(byte);
}
}
None
self.bytes.by_ref().find(|&byte| self.class == self.classes.get(byte))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/util/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl core::fmt::Debug for DebugByte {
let mut len = 0;
for (i, mut b) in core::ascii::escape_default(self.0).enumerate() {
// capitalize \xab to \xAB
if i >= 2 && b'a' <= b && b <= b'f' {
if i >= 2 && (b'a'..=b'f').contains(&b) {
b -= 32;
}
bytes[len] = b;
Expand Down
20 changes: 7 additions & 13 deletions src/util/prefilter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ struct Packed(packed::Searcher);
impl PrefilterI for Packed {
fn find_in(&self, haystack: &[u8], span: Span) -> Candidate {
self.0
.find_in(&haystack, span)
.find_in(haystack, span)
.map_or(Candidate::None, Candidate::Match)
}
}
Expand Down Expand Up @@ -478,7 +478,7 @@ impl core::fmt::Debug for RareByteOffsets {

/// Offsets associated with an occurrence of a "rare" byte in any of the
/// patterns used to construct a single Aho-Corasick automaton.
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Default)]
struct RareByteOffset {
/// The maximum offset at which a particular byte occurs from the start
/// of any pattern. This is used as a shift amount. That is, when an
Expand All @@ -496,12 +496,6 @@ struct RareByteOffset {
max: u8,
}

impl Default for RareByteOffset {
fn default() -> RareByteOffset {
RareByteOffset { max: 0 }
}
}

impl RareByteOffset {
/// Create a new rare byte offset. If the given offset is too big, then
/// None is returned. In that case, callers should render the rare bytes
Expand Down Expand Up @@ -549,7 +543,7 @@ impl RareBytesBuilder {
let (mut bytes, mut len) = ([0; 3], 0);
for b in 0..=255 {
if builder.rare_set.contains(b) {
bytes[len] = b as u8;
bytes[len] = b;
len += 1;
}
}
Expand Down Expand Up @@ -604,7 +598,7 @@ impl RareBytesBuilder {
self.available = false;
return;
}
let mut rarest = match bytes.get(0) {
let mut rarest = match bytes.first() {
None => return,
Some(&b) => (b, freq_rank(b)),
};
Expand Down Expand Up @@ -835,7 +829,7 @@ impl StartBytesBuilder {
if self.count > 3 {
return;
}
if let Some(&byte) = bytes.get(0) {
if let Some(&byte) = bytes.first() {
self.add_one_byte(byte);
if self.ascii_case_insensitive {
self.add_one_byte(opposite_ascii_case(byte));
Expand Down Expand Up @@ -907,9 +901,9 @@ impl PrefilterI for StartBytesThree {
/// e.g., Given `b'A'`, this returns `b'a'`, and given `b'a'`, this returns
/// `b'A'`. If a non-ASCII letter is given, then the given byte is returned.
pub(crate) fn opposite_ascii_case(b: u8) -> u8 {
if b'A' <= b && b <= b'Z' {
if b.is_ascii_uppercase() {
b.to_ascii_lowercase()
} else if b'a' <= b && b <= b'z' {
} else if b.is_ascii_lowercase() {
b.to_ascii_uppercase()
} else {
b
Expand Down