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 {
6666use test:: black_box;
6767use test:: Bencher ;
6868
69+ const ASCII_CASE_MASK : u8 = 0b0010_0000 ;
70+
6971benches ! {
7072 fn case00_alloc_only( _bytes: & mut [ u8 ] ) { }
7173
@@ -204,7 +206,7 @@ benches! {
204206 }
205207 }
206208 for byte in bytes {
207- * byte &= !( ( is_ascii_lowercase( * byte) as u8 ) << 5 )
209+ * byte &= !( ( is_ascii_lowercase( * byte) as u8 ) * ASCII_CASE_MASK )
208210 }
209211 }
210212
@@ -216,7 +218,7 @@ benches! {
216218 }
217219 }
218220 for byte in bytes {
219- * byte -= ( is_ascii_lowercase( * byte) as u8 ) << 5
221+ * byte -= ( is_ascii_lowercase( * byte) as u8 ) * ASCII_CASE_MASK
220222 }
221223 }
222224
Original file line number Diff line number Diff line change 33use crate :: slice;
44use crate :: str:: from_utf8_unchecked_mut;
55use crate :: unicode:: printable:: is_printable;
6- use crate :: unicode:: { self , conversions} ;
6+ use crate :: unicode:: { self , conversions, ASCII_CASE_MASK } ;
77
88use super :: * ;
99
10- /// If 6th bit set ascii is upper case.
11- const ASCII_CASE_MASK : u8 = 0b10_0000u8 ;
12-
1310#[ lang = "char" ]
1411impl char {
1512 /// The highest valid code point a `char` can have.
Original file line number Diff line number Diff line change 55use crate :: intrinsics;
66use crate :: mem;
77use crate :: str:: FromStr ;
8+ use crate :: unicode:: ASCII_CASE_MASK ;
89
910// Used because the `?` operator is not allowed in a const context.
1011macro_rules! try_opt {
@@ -195,7 +196,7 @@ impl u8 {
195196 #[ inline]
196197 pub fn to_ascii_uppercase ( & self ) -> u8 {
197198 // 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 )
199200 }
200201
201202 /// Makes a copy of the value in its ASCII lower case equivalent.
@@ -218,7 +219,7 @@ impl u8 {
218219 #[ inline]
219220 pub fn to_ascii_lowercase ( & self ) -> u8 {
220221 // 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 )
222223 }
223224
224225 /// 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;
1717#[ stable( feature = "unicode_version" , since = "1.45.0" ) ]
1818pub const UNICODE_VERSION : ( u8 , u8 , u8 ) = unicode_data:: UNICODE_VERSION ;
1919
20+ /// If 6th bit set ascii is upper case.
21+ pub ( crate ) const ASCII_CASE_MASK : u8 = 0b0010_0000 ;
22+
2023// For use in liballoc, not re-exported in libstd.
2124pub use unicode_data:: {
2225 case_ignorable:: lookup as Case_Ignorable , cased:: lookup as Cased , conversions,
You can’t perform that action at this time.
0 commit comments