Skip to content

Commit 7142a8c

Browse files
committed
Use SliceIter in SliceFind::find
1 parent 878a035 commit 7142a8c

1 file changed

Lines changed: 3 additions & 11 deletions

File tree

src/slice/mod.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,14 @@ macro_rules! foreach {
119119
}}
120120
}
121121

122+
use self::iter::SliceIter;
123+
122124
impl<T> SliceFind for [T] {
123125
type Item = T;
124126
fn find<U: ?Sized>(&self, elt: &U) -> Option<usize>
125127
where Self::Item: PartialEq<U>
126128
{
127-
let mut xs = self;
128-
let mut i = 0;
129-
const C: usize = 8;
130-
while xs.len() >= C {
131-
foreach!(j in 0, 1, 2, 3, 4, 5, 6, 7 => {
132-
if xs[j] == *elt { return Some(i + j); }
133-
});
134-
i += C;
135-
xs = &xs[C..];
136-
}
137-
xs.iter().position(|x| *x == *elt).map(|j| i + j)
129+
SliceIter::from(self).position(|x| *x == *elt)
138130
}
139131

140132
fn rfind<U: ?Sized>(&self, elt: &U) -> Option<usize>

0 commit comments

Comments
 (0)