diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 8f21f109e81..d5a5e2b4741 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -1953,7 +1953,10 @@ fn trim_right_matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> &'a str #[inline] fn is_char_boundary(&self, index: usize) -> bool { - if index == self.len() { return true; } + // 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() { return true; } match self.as_bytes().get(index) { None => false, Some(&b) => b < 128 || b >= 192, @@ -2026,6 +2029,7 @@ fn find_str<'a, P: Pattern<'a>>(&'a self, pat: P) -> Option { self.find(pat) } + #[inline] fn split_at(&self, mid: usize) -> (&str, &str) { // is_char_boundary checks that the index is in [0, .len()] if self.is_char_boundary(mid) {