Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more efficient is_ascii methods #96141

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions library/core/src/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ impl char {
#[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")]
#[inline]
pub const fn is_ascii_alphabetic(&self) -> bool {
matches!(*self, 'A'..='Z' | 'a'..='z')
(*self as u32 | 0b10_0000).wrapping_sub('a' as u32) < 26
}

/// Checks if the value is an ASCII uppercase character:
Expand Down Expand Up @@ -1380,7 +1380,7 @@ impl char {
#[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")]
#[inline]
pub const fn is_ascii_alphanumeric(&self) -> bool {
matches!(*self, '0'..='9' | 'A'..='Z' | 'a'..='z')
self.is_ascii_digit() || self.is_ascii_alphabetic()
}

/// Checks if the value is an ASCII decimal digit:
Expand Down Expand Up @@ -1451,7 +1451,7 @@ impl char {
#[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")]
#[inline]
pub const fn is_ascii_hexdigit(&self) -> bool {
matches!(*self, '0'..='9' | 'A'..='F' | 'a'..='f')
self.is_ascii_digit() || (*self as u32 | 0b10_0000).wrapping_sub('a' as u32) < 6
}

/// Checks if the value is an ASCII punctuation character:
Expand Down