Skip to content

Commit b4faa9b

Browse files
committed
Remove ASCII_CHARACTER_CLASS table, use match with range patterns instead.
1 parent 6d3840b commit b4faa9b

File tree

1 file changed

+20
-55
lines changed

1 file changed

+20
-55
lines changed

src/libcore/num/mod.rs

Lines changed: 20 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3958,9 +3958,8 @@ impl u8 {
39583958
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
39593959
#[inline]
39603960
pub fn is_ascii_alphabetic(&self) -> bool {
3961-
if *self >= 0x80 { return false; }
3962-
match ASCII_CHARACTER_CLASS[*self as usize] {
3963-
L | Lx | U | Ux => true,
3961+
match *self {
3962+
b'A'...b'Z' | b'a'...b'z' => true,
39643963
_ => false
39653964
}
39663965
}
@@ -3994,9 +3993,8 @@ impl u8 {
39943993
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
39953994
#[inline]
39963995
pub fn is_ascii_uppercase(&self) -> bool {
3997-
if *self >= 0x80 { return false }
3998-
match ASCII_CHARACTER_CLASS[*self as usize] {
3999-
U | Ux => true,
3996+
match *self {
3997+
b'A'...b'Z' => true,
40003998
_ => false
40013999
}
40024000
}
@@ -4030,9 +4028,8 @@ impl u8 {
40304028
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
40314029
#[inline]
40324030
pub fn is_ascii_lowercase(&self) -> bool {
4033-
if *self >= 0x80 { return false }
4034-
match ASCII_CHARACTER_CLASS[*self as usize] {
4035-
L | Lx => true,
4031+
match *self {
4032+
b'a'...b'z' => true,
40364033
_ => false
40374034
}
40384035
}
@@ -4069,9 +4066,8 @@ impl u8 {
40694066
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
40704067
#[inline]
40714068
pub fn is_ascii_alphanumeric(&self) -> bool {
4072-
if *self >= 0x80 { return false }
4073-
match ASCII_CHARACTER_CLASS[*self as usize] {
4074-
D | L | Lx | U | Ux => true,
4069+
match *self {
4070+
b'0'...b'9' | b'A'...b'Z' | b'a'...b'z' => true,
40754071
_ => false
40764072
}
40774073
}
@@ -4105,9 +4101,8 @@ impl u8 {
41054101
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
41064102
#[inline]
41074103
pub fn is_ascii_digit(&self) -> bool {
4108-
if *self >= 0x80 { return false }
4109-
match ASCII_CHARACTER_CLASS[*self as usize] {
4110-
D => true,
4104+
match *self {
4105+
b'0'...b'9' => true,
41114106
_ => false
41124107
}
41134108
}
@@ -4144,9 +4139,8 @@ impl u8 {
41444139
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
41454140
#[inline]
41464141
pub fn is_ascii_hexdigit(&self) -> bool {
4147-
if *self >= 0x80 { return false }
4148-
match ASCII_CHARACTER_CLASS[*self as usize] {
4149-
D | Lx | Ux => true,
4142+
match *self {
4143+
b'0'...b'9' | b'A'...b'F' | b'a'...b'f' => true,
41504144
_ => false
41514145
}
41524146
}
@@ -4184,9 +4178,8 @@ impl u8 {
41844178
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
41854179
#[inline]
41864180
pub fn is_ascii_punctuation(&self) -> bool {
4187-
if *self >= 0x80 { return false }
4188-
match ASCII_CHARACTER_CLASS[*self as usize] {
4189-
P => true,
4181+
match *self {
4182+
b'!'...b'/' | b':'...b'@' | b'['...b'`' | b'{'...b'~' => true,
41904183
_ => false
41914184
}
41924185
}
@@ -4220,9 +4213,8 @@ impl u8 {
42204213
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
42214214
#[inline]
42224215
pub fn is_ascii_graphic(&self) -> bool {
4223-
if *self >= 0x80 { return false; }
4224-
match ASCII_CHARACTER_CLASS[*self as usize] {
4225-
Ux | U | Lx | L | D | P => true,
4216+
match *self {
4217+
b'!'...b'~' => true,
42264218
_ => false
42274219
}
42284220
}
@@ -4273,9 +4265,8 @@ impl u8 {
42734265
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
42744266
#[inline]
42754267
pub fn is_ascii_whitespace(&self) -> bool {
4276-
if *self >= 0x80 { return false; }
4277-
match ASCII_CHARACTER_CLASS[*self as usize] {
4278-
Cw | W => true,
4268+
match *self {
4269+
b'\t' | b'\n' | b'\x0C' | b'\r' | b' ' => true,
42794270
_ => false
42804271
}
42814272
}
@@ -4311,9 +4302,8 @@ impl u8 {
43114302
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
43124303
#[inline]
43134304
pub fn is_ascii_control(&self) -> bool {
4314-
if *self >= 0x80 { return false; }
4315-
match ASCII_CHARACTER_CLASS[*self as usize] {
4316-
C | Cw => true,
4305+
match *self {
4306+
b'\0'...b'\x1F' | b'\x7F' => true,
43174307
_ => false
43184308
}
43194309
}
@@ -4979,28 +4969,3 @@ impl_from! { u32, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0"
49794969

49804970
// Float -> Float
49814971
impl_from! { f32, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")] }
4982-
4983-
enum AsciiCharacterClass {
4984-
C, // control
4985-
Cw, // control whitespace
4986-
W, // whitespace
4987-
D, // digit
4988-
L, // lowercase
4989-
Lx, // lowercase hex digit
4990-
U, // uppercase
4991-
Ux, // uppercase hex digit
4992-
P, // punctuation
4993-
}
4994-
use self::AsciiCharacterClass::*;
4995-
4996-
static ASCII_CHARACTER_CLASS: [AsciiCharacterClass; 128] = [
4997-
// _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _a _b _c _d _e _f
4998-
C, C, C, C, C, C, C, C, C, Cw,Cw,C, Cw,Cw,C, C, // 0_
4999-
C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, // 1_
5000-
W, P, P, P, P, P, P, P, P, P, P, P, P, P, P, P, // 2_
5001-
D, D, D, D, D, D, D, D, D, D, P, P, P, P, P, P, // 3_
5002-
P, Ux,Ux,Ux,Ux,Ux,Ux,U, U, U, U, U, U, U, U, U, // 4_
5003-
U, U, U, U, U, U, U, U, U, U, U, P, P, P, P, P, // 5_
5004-
P, Lx,Lx,Lx,Lx,Lx,Lx,L, L, L, L, L, L, L, L, L, // 6_
5005-
L, L, L, L, L, L, L, L, L, L, L, P, P, P, P, C, // 7_
5006-
];

0 commit comments

Comments
 (0)