about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorGary Linscott <glinscott@gmail.com>2013-07-06 01:54:29 -0400
committerGary Linscott <glinscott@gmail.com>2013-07-06 01:54:29 -0400
commit52949fbf1876ecd03303006c534a74c5e29bc90d (patch)
treec928c856c7740899fb39352c1e632310ef4f3b22 /src/libstd
parent58eb70a5e2ce6602e5685f5cc18ab2fe0c327020 (diff)
downloadrust-52949fbf1876ecd03303006c534a74c5e29bc90d.tar.gz
rust-52949fbf1876ecd03303006c534a74c5e29bc90d.zip
Faster check for ascii-space
Since ' ' is by far one of the most common characters, it is worthwhile
to put it first, and short-circuit the rest of the function.

On the same JSON benchmark, as the json_perf improvement, reading example.json
10 times from https://code.google.com/p/rapidjson/wiki/Performance.

Before: 0.16s
After: 0.11s
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/char.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/libstd/char.rs b/src/libstd/char.rs
index 6a9555f4efc..47473c2faba 100644
--- a/src/libstd/char.rs
+++ b/src/libstd/char.rs
@@ -82,7 +82,8 @@ pub fn is_uppercase(c: char) -> bool { general_category::Lu(c) }
 ///
 #[inline]
 pub fn is_whitespace(c: char) -> bool {
-    ('\x09' <= c && c <= '\x0d')
+    c == ' '
+        || ('\x09' <= c && c <= '\x0d')
         || general_category::Zs(c)
         || general_category::Zl(c)
         || general_category::Zp(c)