about summary refs log tree commit diff
path: root/library/core/src/char
diff options
context:
space:
mode:
authorokaneco <47607823+okaneco@users.noreply.github.com>2023-10-26 20:23:56 -0400
committerokaneco <47607823+okaneco@users.noreply.github.com>2023-10-26 21:48:36 -0400
commit465ffc9ca781af9ac0a89643c9971ac807da5766 (patch)
tree4de6c72d8584d65aa4d27c02c900f3251bca64e5 /library/core/src/char
parent8396efecf7d30ca9f7edcf76aba2ea388300f6ab (diff)
downloadrust-465ffc9ca781af9ac0a89643c9971ac807da5766.tar.gz
rust-465ffc9ca781af9ac0a89643c9971ac807da5766.zip
Refactor some `char`, `u8` ascii functions to be branchless
Decompose singular `matches!` with or-patterns to individual `matches!`
statements to enable branchless code output. The following functions
were changed:
- `is_ascii_alphanumeric`
- `is_ascii_hexdigit`
- `is_ascii_punctuation`

Add codegen tests

Co-authored-by: George Bateman <george.bateman16@gmail.com>
Co-authored-by: scottmcm <scottmcm@users.noreply.github.com>
Diffstat (limited to 'library/core/src/char')
-rw-r--r--library/core/src/char/methods.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs
index 4ac956e7b76..7ce33bdd411 100644
--- a/library/core/src/char/methods.rs
+++ b/library/core/src/char/methods.rs
@@ -1450,7 +1450,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')
+        matches!(*self, '0'..='9') | matches!(*self, 'A'..='Z') | matches!(*self, 'a'..='z')
     }
 
     /// Checks if the value is an ASCII decimal digit:
@@ -1553,7 +1553,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')
+        matches!(*self, '0'..='9') | matches!(*self, 'A'..='F') | matches!(*self, 'a'..='f')
     }
 
     /// Checks if the value is an ASCII punctuation character:
@@ -1591,7 +1591,10 @@ impl char {
     #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")]
     #[inline]
     pub const fn is_ascii_punctuation(&self) -> bool {
-        matches!(*self, '!'..='/' | ':'..='@' | '['..='`' | '{'..='~')
+        matches!(*self, '!'..='/')
+            | matches!(*self, ':'..='@')
+            | matches!(*self, '['..='`')
+            | matches!(*self, '{'..='~')
     }
 
     /// Checks if the value is an ASCII graphic character: