From 52949fbf1876ecd03303006c534a74c5e29bc90d Mon Sep 17 00:00:00 2001 From: Gary Linscott Date: Sat, 6 Jul 2013 01:54:29 -0400 Subject: [PATCH] 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 --- src/libstd/char.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libstd/char.rs b/src/libstd/char.rs index 6a9555f4efcd..47473c2faba6 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)