diff options
| author | Karl Meakin <karl.meakin@arm.com> | 2025-08-07 00:05:22 +0100 |
|---|---|---|
| committer | Karl Meakin <karl.meakin@arm.com> | 2025-08-07 00:08:11 +0100 |
| commit | bf5020937f17fd4c2f8ae5e7703fd9b8d15f0502 (patch) | |
| tree | 2b4b06b76d0a233bedd9a8c507ee0c4aafec3ed7 | |
| parent | 29cdc6a109ee98a382f974bf89d3971b4385399c (diff) | |
| download | rust-bf5020937f17fd4c2f8ae5e7703fd9b8d15f0502.tar.gz rust-bf5020937f17fd4c2f8ae5e7703fd9b8d15f0502.zip | |
Optimize `char::is_alphanumeric`
Avoid an unnecessary call to `unicode::Alphabetic` when `self` is an ASCII digit (ie `0..=9`).
| -rw-r--r-- | library/core/src/char/methods.rs | 6 |
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. |
