str: add ASCII fast path to word_to_titlecase#159271
Conversation
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @clarfonthey (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
| } | ||
|
|
||
| #[test] | ||
| fn word_to_titlecase() { |
There was a problem hiding this comment.
If we're going to add titlecase tests, we should at least add some weird cases. What felt reasonable to test was the three LJ ligatures (lower lj, upper LJ, title Lj) and one character that decomposes into title case (lower ß, upper SS, title Ss):
ßljLJLj=>SsljljljljLJLjß=>LjljljßLJLjßlj=>LjljßljLjßljLJ=>Ljßljlj
The word_to_titlecase function had a FIXME comment since a long time asking to add a fast path for ASCII text.
Before this change, even simple English text like "hello world" was going through slow Unicode lookup tables. That was unnecessary.
This fixes it by using the same trick that to_lowercase already uses — plain English letters are now handled much faster, and only Greek/Chinese/etc still use the Unicode tables.
No behavior changes, just faster for normal English text.