diff options
| author | Karl Meakin <karl.meakin@arm.com> | 2025-08-02 23:32:10 +0100 |
|---|---|---|
| committer | Karl Meakin <karl.meakin@arm.com> | 2025-09-07 15:21:24 +0200 |
| commit | a8c669461f0c71985c72dd5b05f70b8d4d149e3b (patch) | |
| tree | 9319ed6acf4501829107836c660d74bf32dfa6a4 /library/alloc/src | |
| parent | fbd8f95118fff54a2402983d3f446cad9b2f30c5 (diff) | |
| download | rust-a8c669461f0c71985c72dd5b05f70b8d4d149e3b.tar.gz rust-a8c669461f0c71985c72dd5b05f70b8d4d149e3b.zip | |
optimization: Don't include ASCII characters in Unicode tables
The ASCII subset of Unicode is fixed and will never change, so we don't need to generate tables for it with every new Unicode version. This saves a few bytes of static data and speeds up `char::is_control` and `char::is_grapheme_extended` on ASCII inputs. Since the table lookup functions exported from the `unicode` module will give nonsensical errors on ASCII input (and in fact will panic in debug mode), I had to add some private wrapper methods to `char` which check for ASCII-ness first.
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/str.rs | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index 22cdd8ecde0..e772ac25a95 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -418,9 +418,8 @@ impl str { } fn case_ignorable_then_cased<I: Iterator<Item = char>>(iter: I) -> bool { - use core::unicode::{Case_Ignorable, Cased}; - match iter.skip_while(|&c| Case_Ignorable(c)).next() { - Some(c) => Cased(c), + match iter.skip_while(|&c| c.is_case_ignorable()).next() { + Some(c) => c.is_cased(), None => false, } } |
