about summary refs log tree commit diff
path: root/library
diff options
context:
space:
mode:
authorStuart Cook <Zalathar@users.noreply.github.com>2025-08-09 13:58:47 +1000
committerGitHub <noreply@github.com>2025-08-09 13:58:47 +1000
commit2a7354e03e206c941258c9c6406229375de089d9 (patch)
treea10bba929e56c47013604e6c6d2f44b9ffab2992 /library
parentaa7cb5396e6e431632d1c285a6ed6a528128b9e8 (diff)
parentbf5020937f17fd4c2f8ae5e7703fd9b8d15f0502 (diff)
downloadrust-2a7354e03e206c941258c9c6406229375de089d9.tar.gz
rust-2a7354e03e206c941258c9c6406229375de089d9.zip
Rollup merge of #145027 - Kmeakin:km/optimize-char-is-alphanumeric, r=scottmcm
Optimize `char::is_alphanumeric`

Avoid an unnecessary call to `unicode::Alphabetic` when `self` is an ASCII digit (ie `0..=9`).
Diffstat (limited to 'library')
-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 b0752a85faf..7ee0962721f 100644
--- a/library/core/src/char/methods.rs
+++ b/library/core/src/char/methods.rs
@@ -920,7 +920,11 @@ impl char {
     #[stable(feature = "rust1", since = "1.0.0")]
     #[inline]
     pub fn is_alphanumeric(self) -> bool {
-        self.is_alphabetic() || self.is_numeric()
+        if self.is_ascii() {
+            self.is_ascii_alphanumeric()
+        } else {
+            unicode::Alphabetic(self) || unicode::N(self)
+        }
     }
 
     /// Returns `true` if this `char` has the general category for control codes.