Rollup merge of #32862 - raphlinus:master, r=bluss

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
This commit is contained in:
Steve Klabnik 2016-04-11 10:31:28 -04:00
commit c5842837b8

View File

@ -1940,7 +1940,8 @@ impl StrExt for str {
if index == 0 || index == self.len() { return true; } if index == 0 || index == self.len() { return true; }
match self.as_bytes().get(index) { match self.as_bytes().get(index) {
None => false, None => false,
Some(&b) => b < 128 || b >= 192, // This is bit magic equivalent to: b < 128 || b >= 192
Some(&b) => (b as i8) >= -0x40,
} }
} }