Skip to content

Commit 4eb9e66

Browse files
Extend ASCII fast paths of char methods beyond ASCII
1 parent 35f1109 commit 4eb9e66

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

library/core/src/char/methods.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,9 @@ impl char {
777777
#[inline]
778778
pub fn is_alphabetic(self) -> bool {
779779
match self {
780-
'a'..='z' | 'A'..='Z' => true,
781-
c => c > '\x7f' && unicode::Alphabetic(c),
780+
'A'..='Z' | 'a'..='z' => true,
781+
'\0'..='\u{A9}' => false,
782+
_ => unicode::Alphabetic(self),
782783
}
783784
}
784785

@@ -819,7 +820,8 @@ impl char {
819820
pub const fn is_lowercase(self) -> bool {
820821
match self {
821822
'a'..='z' => true,
822-
c => c > '\x7f' && unicode::Lowercase(c),
823+
'\0'..='\u{A9}' => false,
824+
_ => unicode::Lowercase(self),
823825
}
824826
}
825827

@@ -860,7 +862,8 @@ impl char {
860862
pub const fn is_uppercase(self) -> bool {
861863
match self {
862864
'A'..='Z' => true,
863-
c => c > '\x7f' && unicode::Uppercase(c),
865+
'\0'..='\u{BF}' => false,
866+
_ => unicode::Uppercase(self),
864867
}
865868
}
866869

@@ -893,7 +896,8 @@ impl char {
893896
pub const fn is_whitespace(self) -> bool {
894897
match self {
895898
' ' | '\x09'..='\x0d' => true,
896-
c => c > '\x7f' && unicode::White_Space(c),
899+
'\0'..='\u{84}' => false,
900+
_ => unicode::White_Space(self),
897901
}
898902
}
899903

@@ -920,10 +924,10 @@ impl char {
920924
#[stable(feature = "rust1", since = "1.0.0")]
921925
#[inline]
922926
pub fn is_alphanumeric(self) -> bool {
923-
if self.is_ascii() {
924-
self.is_ascii_alphanumeric()
925-
} else {
926-
unicode::Alphabetic(self) || unicode::N(self)
927+
match self {
928+
'0'..='9' | 'A'..='Z' | 'a'..='z' => true,
929+
'\0'..='\u{A9}' => false,
930+
_ => unicode::Alphabetic(self) || unicode::N(self),
927931
}
928932
}
929933

@@ -969,7 +973,7 @@ impl char {
969973
#[must_use]
970974
#[inline]
971975
pub(crate) fn is_grapheme_extended(self) -> bool {
972-
!self.is_ascii() && unicode::Grapheme_Extend(self)
976+
self > '\u{02FF}' && unicode::Grapheme_Extend(self)
973977
}
974978

975979
/// Returns `true` if this `char` has the `Cased` property.
@@ -985,7 +989,11 @@ impl char {
985989
#[doc(hidden)]
986990
#[unstable(feature = "char_internals", reason = "exposed only for libstd", issue = "none")]
987991
pub fn is_cased(self) -> bool {
988-
if self.is_ascii() { self.is_ascii_alphabetic() } else { unicode::Cased(self) }
992+
match self {
993+
'A'..='Z' | 'a'..='z' => true,
994+
'\0'..='\u{A9}' => false,
995+
_ => unicode::Cased(self),
996+
}
989997
}
990998

991999
/// Returns `true` if this `char` has the `Case_Ignorable` property.
@@ -1047,7 +1055,8 @@ impl char {
10471055
pub fn is_numeric(self) -> bool {
10481056
match self {
10491057
'0'..='9' => true,
1050-
c => c > '\x7f' && unicode::N(c),
1058+
'\0'..='\u{B1}' => false,
1059+
_ => unicode::N(self),
10511060
}
10521061
}
10531062

0 commit comments

Comments
 (0)