File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed
Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -102,9 +102,10 @@ pub fn eq_ignore_ascii_case(a: &[u8], b: &[u8]) -> bool {
102102
103103#[ inline( always) ]
104104pub fn eq_ignore_ascii_case_char ( a : u8 , b : u8 ) -> bool {
105- // Branchless check for alphabetic
106- let is_alpha_mask = ( ( a | b) . wrapping_sub ( b'A' ) <= ( b'Z' - b'A' ) ) as u8 ;
107- a == b || ( a ^ b == 0b00100000 && is_alpha_mask == 1 )
105+ // Branchless check for ASCII alphabetic
106+ let a_up = a & !0b0010_0000 ;
107+ let b_up = b & !0b0010_0000 ;
108+ ( a_up == b_up && a_up >= b'A' && a_up <= b'Z' ) || a == b
108109}
109110
110111#[ cfg( test) ]
@@ -137,8 +138,13 @@ mod tests {
137138
138139 #[ test]
139140 fn test_eq_ignore_ascii_case ( ) {
140- for x in b'a' ..=b'z' {
141- assert ! ( eq_ignore_ascii_case_char( x, x. to_ascii_uppercase( ) ) ) ;
141+
142+ for range in [ b'a' ..=b'z' , b'A' ..=b'Z' ] {
143+ for x in range {
144+ let y = x. to_ascii_uppercase ( ) ;
145+ println ! ( "Testing {} and {}" , x as char , y as char ) ;
146+ assert ! ( eq_ignore_ascii_case_char( x, y) ) ;
147+ }
142148 }
143149
144150 assert ! ( !eq_ignore_ascii_case_char( b'a' , b'b' ) ) ;
You can’t perform that action at this time.
0 commit comments