mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 22:53:28 +00:00
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
This commit is contained in:
parent
cecdb181ad
commit
e48c68479e
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user