File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -35,3 +35,13 @@ fn bench_to_digit_radix_var(b: &mut Bencher) {
3535 . min ( )
3636 } )
3737}
38+
39+ #[ bench]
40+ fn bench_to_ascii_uppercase ( b : & mut Bencher ) {
41+ b. iter ( || CHARS . iter ( ) . cycle ( ) . take ( 10_000 ) . map ( |c| c. to_ascii_uppercase ( ) ) . min ( ) )
42+ }
43+
44+ #[ bench]
45+ fn bench_to_ascii_lowercase ( b : & mut Bencher ) {
46+ b. iter ( || CHARS . iter ( ) . cycle ( ) . take ( 10_000 ) . map ( |c| c. to_ascii_lowercase ( ) ) . min ( ) )
47+ }
Original file line number Diff line number Diff line change @@ -1090,7 +1090,8 @@ impl char {
10901090 #[ stable( feature = "ascii_methods_on_intrinsics" , since = "1.23.0" ) ]
10911091 #[ inline]
10921092 pub fn to_ascii_uppercase ( & self ) -> char {
1093- if self . is_ascii ( ) { ( * self as u8 ) . to_ascii_uppercase ( ) as char } else { * self }
1093+ // 6th bit dictates ascii case.
1094+ if self . is_ascii_lowercase ( ) { ( ( * self as u8 ) & !0b10_0000u8 ) as char } else { * self }
10941095 }
10951096
10961097 /// Makes a copy of the value in its ASCII lower case equivalent.
@@ -1118,7 +1119,8 @@ impl char {
11181119 #[ stable( feature = "ascii_methods_on_intrinsics" , since = "1.23.0" ) ]
11191120 #[ inline]
11201121 pub fn to_ascii_lowercase ( & self ) -> char {
1121- if self . is_ascii ( ) { ( * self as u8 ) . to_ascii_lowercase ( ) as char } else { * self }
1122+ // 6th bit dictates ascii case.
1123+ if self . is_ascii_uppercase ( ) { ( ( * self as u8 ) | 0b10_0000u8 ) as char } else { * self }
11221124 }
11231125
11241126 /// Checks that two values are an ASCII case-insensitive match.
You can’t perform that action at this time.
0 commit comments