about summary refs log tree commit diff
path: root/library/core/src/char/methods.rs
diff options
context:
space:
mode:
authorKarl Meakin <karl.meakin@arm.com>2025-08-11 00:57:29 +0000
committerKarl Meakin <karl.meakin@arm.com>2025-08-16 01:46:30 +0100
commit1bb9b151c9f9b5116254827f04add845aff33408 (patch)
treef7d3847093f8b44c7512ac5317c9034145048f29 /library/core/src/char/methods.rs
parentcd7cbe818e4a66d46fe2df993d1b8518eba8a5cd (diff)
downloadrust-1bb9b151c9f9b5116254827f04add845aff33408.tar.gz
rust-1bb9b151c9f9b5116254827f04add845aff33408.zip
refactor: Hard-code `char::is_control`
According to
https://www.unicode.org/policies/stability_policy.html#Property_Value,
the set of codepoints in `Cc` will never change. So we can hard-code
the patterns to match against instead of using a table.
Diffstat (limited to 'library/core/src/char/methods.rs')
-rw-r--r--library/core/src/char/methods.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs
index 7ee0962721f..61ac7f8a339 100644
--- a/library/core/src/char/methods.rs
+++ b/library/core/src/char/methods.rs
@@ -950,7 +950,11 @@ impl char {
     #[stable(feature = "rust1", since = "1.0.0")]
     #[inline]
     pub fn is_control(self) -> bool {
-        unicode::Cc(self)
+        // According to
+        // https://www.unicode.org/policies/stability_policy.html#Property_Value,
+        // the set of codepoints in `Cc` will never change.
+        // So we can just hard-code the patterns to match against instead of using a table.
+        matches!(self, '\0'..='\x1f' | '\x7f'..='\u{9f}')
     }
 
     /// Returns `true` if this `char` has the `Grapheme_Extend` property.