Skip to content

Commit

Permalink
str::is_char_boundary - slight optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Soveu committed Apr 30, 2021
1 parent 49920bc commit 2ea0410
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/core/src/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ impl str {
// 0 and len are always ok.
// Test for 0 explicitly so that it can optimize out the check
// easily and skip reading string data for that case.
if index == 0 || index == self.len() {
if index == 0 {
return true;
}
match self.as_bytes().get(index) {
None => false,
None => index == self.len(),
// This is bit magic equivalent to: b < 128 || b >= 192
Some(&b) => (b as i8) >= -0x40,
}
Expand Down

0 comments on commit 2ea0410

Please sign in to comment.