Skip to content

Commit d466fd0

Browse files
committed
Slightly simplify find_char_midpoint
1 parent 733c6f6 commit d466fd0

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/str.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ fn find_char_midpoint(chars: &str) -> usize {
3535
// character boundary. So we look at the raw bytes, first scanning
3636
// forward from the midpoint for a boundary, then trying backward.
3737
let (left, right) = chars.as_bytes().split_at(mid);
38-
right.iter()
39-
.cloned()
40-
.position(is_char_boundary)
41-
.map(|i| mid + i)
42-
.or_else(|| left.iter().cloned().rposition(is_char_boundary))
43-
.unwrap_or(0)
38+
match right.iter().cloned().position(is_char_boundary) {
39+
Some(i) => mid + i,
40+
None => left.iter()
41+
.cloned()
42+
.rposition(is_char_boundary)
43+
.unwrap_or(0),
44+
}
4445
}
4546

4647
/// Try to split a string near the midpoint.

0 commit comments

Comments
 (0)