From c5b128a4cbcac07cf8d72207192263c6164098ad Mon Sep 17 00:00:00 2001 From: 1ndahous3 <9205230+1ndahous3@users.noreply.github.com> Date: Sat, 26 Sep 2026 15:45:15 +0300 Subject: [PATCH] Map ASCII case without ICU in simple_lowercase/simple_uppercase (#8833) Assisted-by: Claude Code:claude-opus-5-5 --- crates/unicode/src/case.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/unicode/src/case.rs b/crates/unicode/src/case.rs index c563db093..d5dd4c3b6 100644 --- a/crates/unicode/src/case.rs +++ b/crates/unicode/src/case.rs @@ -33,12 +33,18 @@ use writeable::Writeable; /// Simple (one-to-one) lowercase mapping of `c` (`Py_UNICODE_TOLOWER`). #[must_use] pub fn simple_lowercase(c: char) -> char { + if c.is_ascii() { + return c.to_ascii_lowercase(); + } CaseMapper::new().simple_lowercase(c) } /// Simple (one-to-one) uppercase mapping of `c` (`Py_UNICODE_TOUPPER`). #[must_use] pub fn simple_uppercase(c: char) -> char { + if c.is_ascii() { + return c.to_ascii_uppercase(); + } CaseMapper::new().simple_uppercase(c) } @@ -379,6 +385,15 @@ mod tests { assert_eq!(capitalize_str("ßhello"), "Sshello"); } + #[test] + fn ascii_fast_path_matches_icu() { + let mapper = icu_casemap::CaseMapper::new(); + for c in (0u8..0x80).map(char::from) { + assert_eq!(simple_lowercase(c), mapper.simple_lowercase(c)); + assert_eq!(simple_uppercase(c), mapper.simple_uppercase(c)); + } + } + #[test] fn wtf8_passes_surrogates_through() { let mut buf = Wtf8Buf::from("ab cd");