diff options
| author | Miccah Castorina <m.castorina93@gmail.com> | 2021-01-24 16:03:38 -0600 |
|---|---|---|
| committer | Miccah Castorina <m.castorina93@gmail.com> | 2021-02-26 11:39:36 -0600 |
| commit | e48c68479eb9f898154843dd2ae291d53df952a3 (patch) | |
| tree | 8c81c1a7020a756b6cb0b1e5d7a008502994a739 | |
| parent | cecdb181ade91c0a5ffab9a148dba68fc7d00ee3 (diff) | |
| download | rust-e48c68479eb9f898154843dd2ae291d53df952a3.tar.gz rust-e48c68479eb9f898154843dd2ae291d53df952a3.zip | |
Add a check for ASCII characters in to_upper and to_lower
This extra check has better performance. See discussion here: https://internals.rust-lang.org/t/to-upper-speed/13896
| -rw-r--r-- | library/core/src/unicode/unicode_data.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/library/core/src/unicode/unicode_data.rs b/library/core/src/unicode/unicode_data.rs index 9c92a8ba28a..16803bf2e83 100644 --- a/library/core/src/unicode/unicode_data.rs +++ b/library/core/src/unicode/unicode_data.rs @@ -549,16 +549,24 @@ pub mod white_space { #[rustfmt::skip] pub mod conversions { pub fn to_lower(c: char) -> [char; 3] { - match bsearch_case_table(c, LOWERCASE_TABLE) { - None => [c, '\0', '\0'], - Some(index) => LOWERCASE_TABLE[index].1, + if c.is_ascii() { + [(c as u8).to_ascii_lowercase() as char, '\0', '\0'] + } else { + match bsearch_case_table(c, LOWERCASE_TABLE) { + None => [c, '\0', '\0'], + Some(index) => LOWERCASE_TABLE[index].1, + } } } pub fn to_upper(c: char) -> [char; 3] { - match bsearch_case_table(c, UPPERCASE_TABLE) { - None => [c, '\0', '\0'], - Some(index) => UPPERCASE_TABLE[index].1, + if c.is_ascii() { + [(c as u8).to_ascii_uppercase() as char, '\0', '\0'] + } else { + match bsearch_case_table(c, UPPERCASE_TABLE) { + None => [c, '\0', '\0'], + Some(index) => UPPERCASE_TABLE[index].1, + } } } |
