diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-08-09 13:58:47 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-09 13:58:47 +1000 |
| commit | 2a7354e03e206c941258c9c6406229375de089d9 (patch) | |
| tree | a10bba929e56c47013604e6c6d2f44b9ffab2992 /library | |
| parent | aa7cb5396e6e431632d1c285a6ed6a528128b9e8 (diff) | |
| parent | bf5020937f17fd4c2f8ae5e7703fd9b8d15f0502 (diff) | |
| download | rust-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.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. |
