about summary refs log tree commit diff
path: root/src/libcore/str
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2016-04-09 17:11:20 -0700
committerRaph Levien <raph@google.com>2016-04-09 17:16:54 -0700
commitb2db97347bc4373deea24eb7b7c6ecffb117fd8c (patch)
treeb56edebcd2012961de7fa7ecb829bb4c5afd2869 /src/libcore/str
parent526f2bf5c534308193246e13ab2da8b3c0cf3cbb (diff)
downloadrust-b2db97347bc4373deea24eb7b7c6ecffb117fd8c.tar.gz
rust-b2db97347bc4373deea24eb7b7c6ecffb117fd8c.zip
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
Diffstat (limited to 'src/libcore/str')
-rw-r--r--src/libcore/str/mod.rs3
1 files changed, 2 insertions, 1 deletions
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,
         }
     }