From b2db97347bc4373deea24eb7b7c6ecffb117fd8c Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Sat, 9 Apr 2016 17:11:20 -0700 Subject: [PATCH] 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 --- src/libcore/str/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 305546df5be..f1be10da872 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -1940,7 +1940,8 @@ impl StrExt for str { if index == 0 || index == self.len() { return true; } match self.as_bytes().get(index) { None => false, - Some(&b) => b < 128 || b >= 192, + // This is bit magic equivalent to: b < 128 || b >= 192 + Some(&b) => (b as i8) >= -0x40, } }