From a8c669461f0c71985c72dd5b05f70b8d4d149e3b Mon Sep 17 00:00:00 2001 From: Karl Meakin Date: Sat, 2 Aug 2025 23:32:10 +0100 Subject: 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. --- library/alloc/src/str.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'library/alloc/src') 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>(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, } } -- cgit 1.4.1-3-g733a5