Skip to content

Commit

Permalink
Faster check for ascii-space
Browse files Browse the repository at this point in the history
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
  • Loading branch information
glinscott committed Jul 6, 2013
1 parent 58eb70a commit 52949fb
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/libstd/char.rs
Expand Up @@ -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)
Expand Down

0 comments on commit 52949fb

Please sign in to comment.