Skip to content

Commit 52949fb

Browse files
committed
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
1 parent 58eb70a commit 52949fb

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/libstd/char.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ pub fn is_uppercase(c: char) -> bool { general_category::Lu(c) }
8282
///
8383
#[inline]
8484
pub fn is_whitespace(c: char) -> bool {
85-
('\x09' <= c && c <= '\x0d')
85+
c == ' '
86+
|| ('\x09' <= c && c <= '\x0d')
8687
|| general_category::Zs(c)
8788
|| general_category::Zl(c)
8889
|| general_category::Zp(c)

0 commit comments

Comments
 (0)