I thought I'd check if there's any reason this hasn't already been done:
In conversions::to_upper
we can check if the char is ascii and skip the binary search by adding in a is_ascii() check.
pub fn to_upper(c: char) -> [char; 3] {
if c.is_ascii() {
[(c as u8).to_ascii_uppercase() as char, '\0', '\0']
} else {
match bsearch_case_table(c, to_uppercase_table) {
None => [c, '\0', '\0'],
Some(index) => to_uppercase_table[index].1,
}
}
}
It speeds up ascii char conversion which seems like a very common case for the cost of one comparison.
The reason I'm asking this is that I'm seeing people learning rust trying to code this kind of thing in as they find that the current to_upper is not as fast as it could be. I figure that maybe we just be fast by default unless this is in some way incorrect?