/// Note that there might be more than one `Reject` between two `Match`es,
/// there is no requirement for them to be combined into one.
Reject(usize, usize),
- /// Expresses that every byte of the haystack has been visted, ending
+ /// Expresses that every byte of the haystack has been visited, ending
/// the iteration.
Done
}
/// the haystack. This enables consumers of this trait to
/// slice the haystack without additional runtime checks.
pub unsafe trait Searcher<'a> {
- /// Getter for the underlaying string to be searched in
+ /// Getter for the underlying string to be searched in
///
/// Will always return the same `&str`
fn haystack(&self) -> &'a str;
fn into_searcher(self, haystack: &'a str) -> CharEqSearcher<'a, C> {
CharEqSearcher {
ascii_only: self.0.only_ascii(),
- haystack: haystack,
+ haystack,
char_eq: self.0,
char_indices: haystack.char_indices(),
}
fn new(haystack: &'a str, needle: &'b str) -> StrSearcher<'a, 'b> {
if needle.is_empty() {
StrSearcher {
- haystack: haystack,
- needle: needle,
+ haystack,
+ needle,
searcher: StrSearcherImpl::Empty(EmptyNeedle {
position: 0,
end: haystack.len(),
}
} else {
StrSearcher {
- haystack: haystack,
- needle: needle,
+ haystack,
+ needle,
searcher: StrSearcherImpl::TwoWay(
TwoWaySearcher::new(needle.as_bytes(), haystack.len())
),
}
unsafe impl<'a, 'b> Searcher<'a> for StrSearcher<'a, 'b> {
- fn haystack(&self) -> &'a str { self.haystack }
+ #[inline]
+ fn haystack(&self) -> &'a str {
+ self.haystack
+ }
#[inline]
fn next(&mut self) -> SearchStep {
}
}
- #[inline(always)]
+ #[inline]
fn next_match(&mut self) -> Option<(usize, usize)> {
match self.searcher {
StrSearcherImpl::Empty(..) => {
TwoWaySearcher::reverse_maximal_suffix(needle, period, true));
TwoWaySearcher {
- crit_pos: crit_pos,
- crit_pos_back: crit_pos_back,
- period: period,
+ crit_pos,
+ crit_pos_back,
+ period,
byteset: Self::byteset_create(&needle[..period]),
position: 0,
- end: end,
+ end,
memory: 0,
memory_back: needle.len(),
}
// reverse search.
TwoWaySearcher {
- crit_pos: crit_pos,
+ crit_pos,
crit_pos_back: crit_pos,
period: cmp::max(crit_pos, needle.len() - crit_pos) + 1,
byteset: Self::byteset_create(needle),
position: 0,
- end: end,
+ end,
memory: usize::MAX, // Dummy value to signify that the period is long
memory_back: usize::MAX,
}
bytes.iter().fold(0, |a, &b| (1 << (b & 0x3f)) | a)
}
- #[inline(always)]
+ #[inline]
fn byteset_contains(&self, byte: u8) -> bool {
(self.byteset >> ((byte & 0x3f) as usize)) & 1 != 0
}
// left to right. If v matches, we try to match u by scanning right to left.
// How far we can jump when we encounter a mismatch is all based on the fact
// that (u, v) is a critical factorization for the needle.
- #[inline(always)]
+ #[inline]
fn next<S>(&mut self, haystack: &[u8], needle: &[u8], long_period: bool)
-> S::Output
where S: TwoWayStrategy
// The maximal suffix is a possible critical factorization (u', v') of `arr`.
//
// Returns `i` where `i` is the starting index of v', from the back;
- // returns immedately when a period of `known_period` is reached.
+ // returns immediately when a period of `known_period` is reached.
//
// `order_greater` determines if lexical order is `<` or `>`. Both
// orders must be computed -- the ordering with the largest `i` gives