Skip to content

Commit 595dd84

Browse files
author
blake2-ppc
committed
std::str: Use CharOffsetIterator in .find() and .rfind()
1 parent db3eb72 commit 595dd84

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/libstd/str.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,10 +1790,8 @@ impl<'self> StrSlice<'self> for &'self str {
17901790
if search.matches(b as char) { return Some(i) }
17911791
}
17921792
} else {
1793-
let mut index = 0;
1794-
for c in self.iter() {
1793+
for (index, c) in self.char_offset_iter() {
17951794
if search.matches(c) { return Some(index); }
1796-
index += c.len_utf8_bytes();
17971795
}
17981796
}
17991797
@@ -1807,15 +1805,14 @@ impl<'self> StrSlice<'self> for &'self str {
18071805
/// `Some` containing the byte index of the last matching character
18081806
/// or `None` if there is no match
18091807
fn rfind<C: CharEq>(&self, search: C) -> Option<uint> {
1810-
let mut index = self.len();
18111808
if search.only_ascii() {
1809+
let mut index = self.len();
18121810
for b in self.byte_rev_iter() {
18131811
index -= 1;
18141812
if search.matches(b as char) { return Some(index); }
18151813
}
18161814
} else {
1817-
for c in self.rev_iter() {
1818-
index -= c.len_utf8_bytes();
1815+
for (index, c) in self.char_offset_rev_iter() {
18191816
if search.matches(c) { return Some(index); }
18201817
}
18211818
}

0 commit comments

Comments
 (0)