Skip to content

Commit b2db973

Browse files
committed
Bit-magic for faster is_char_boundary
The asm generated for b < 128 || b >= 192 is not ideal, as it computes both sub-inequalities. This patch replaces it with bit magic. Fixes #32471
1 parent 526f2bf commit b2db973

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/libcore/str/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,8 @@ impl StrExt for str {
19401940
if index == 0 || index == self.len() { return true; }
19411941
match self.as_bytes().get(index) {
19421942
None => false,
1943-
Some(&b) => b < 128 || b >= 192,
1943+
// This is bit magic equivalent to: b < 128 || b >= 192
1944+
Some(&b) => (b as i8) >= -0x40,
19441945
}
19451946
}
19461947

0 commit comments

Comments
 (0)