File tree Expand file tree Collapse file tree 4 files changed +11
-8
lines changed Expand file tree Collapse file tree 4 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,8 @@ macro_rules! benches {
66
66
use test:: black_box;
67
67
use test:: Bencher ;
68
68
69
+ const ASCII_CASE_MASK : u8 = 0b0010_0000 ;
70
+
69
71
benches ! {
70
72
fn case00_alloc_only( _bytes: & mut [ u8 ] ) { }
71
73
@@ -204,7 +206,7 @@ benches! {
204
206
}
205
207
}
206
208
for byte in bytes {
207
- * byte &= !( ( is_ascii_lowercase( * byte) as u8 ) << 5 )
209
+ * byte &= !( ( is_ascii_lowercase( * byte) as u8 ) * ASCII_CASE_MASK )
208
210
}
209
211
}
210
212
@@ -216,7 +218,7 @@ benches! {
216
218
}
217
219
}
218
220
for byte in bytes {
219
- * byte -= ( is_ascii_lowercase( * byte) as u8 ) << 5
221
+ * byte -= ( is_ascii_lowercase( * byte) as u8 ) * ASCII_CASE_MASK
220
222
}
221
223
}
222
224
Original file line number Diff line number Diff line change 3
3
use crate :: slice;
4
4
use crate :: str:: from_utf8_unchecked_mut;
5
5
use crate :: unicode:: printable:: is_printable;
6
- use crate :: unicode:: { self , conversions} ;
6
+ use crate :: unicode:: { self , conversions, ASCII_CASE_MASK } ;
7
7
8
8
use super :: * ;
9
9
10
- /// If 6th bit set ascii is upper case.
11
- const ASCII_CASE_MASK : u8 = 0b10_0000u8 ;
12
-
13
10
#[ lang = "char" ]
14
11
impl char {
15
12
/// The highest valid code point a `char` can have.
Original file line number Diff line number Diff line change 5
5
use crate :: intrinsics;
6
6
use crate :: mem;
7
7
use crate :: str:: FromStr ;
8
+ use crate :: unicode:: ASCII_CASE_MASK ;
8
9
9
10
// Used because the `?` operator is not allowed in a const context.
10
11
macro_rules! try_opt {
@@ -195,7 +196,7 @@ impl u8 {
195
196
#[ inline]
196
197
pub fn to_ascii_uppercase ( & self ) -> u8 {
197
198
// Unset the fifth bit if this is a lowercase letter
198
- * self & !( ( self . is_ascii_lowercase ( ) as u8 ) << 5 )
199
+ * self & !( ( self . is_ascii_lowercase ( ) as u8 ) * ASCII_CASE_MASK )
199
200
}
200
201
201
202
/// Makes a copy of the value in its ASCII lower case equivalent.
@@ -218,7 +219,7 @@ impl u8 {
218
219
#[ inline]
219
220
pub fn to_ascii_lowercase ( & self ) -> u8 {
220
221
// Set the fifth bit if this is an uppercase letter
221
- * self | ( ( self . is_ascii_uppercase ( ) as u8 ) << 5 )
222
+ * self | ( self . is_ascii_uppercase ( ) as u8 * ASCII_CASE_MASK )
222
223
}
223
224
224
225
/// Checks that two values are an ASCII case-insensitive match.
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ mod unicode_data;
17
17
#[ stable( feature = "unicode_version" , since = "1.45.0" ) ]
18
18
pub const UNICODE_VERSION : ( u8 , u8 , u8 ) = unicode_data:: UNICODE_VERSION ;
19
19
20
+ /// If 6th bit set ascii is upper case.
21
+ pub ( crate ) const ASCII_CASE_MASK : u8 = 0b0010_0000 ;
22
+
20
23
// For use in liballoc, not re-exported in libstd.
21
24
pub use unicode_data:: {
22
25
case_ignorable:: lookup as Case_Ignorable , cased:: lookup as Cased , conversions,
You can’t perform that action at this time.
0 commit comments