File tree Expand file tree Collapse file tree 1 file changed +6
-12
lines changed Expand file tree Collapse file tree 1 file changed +6
-12
lines changed Original file line number Diff line number Diff line change @@ -132,23 +132,17 @@ impl<'a> ToCss for Token<'a> {
132132 }
133133}
134134
135- fn to_hex_byte ( value : u8 ) -> u8 {
136- match value {
137- 0 ...9 => value + b'0' ,
138- _ => value - 10 + b'a' ,
139- }
140- }
141-
142135fn hex_escape < W > ( ascii_byte : u8 , dest : & mut W ) -> fmt:: Result where W : fmt:: Write {
143- let high = ascii_byte >> 4 ;
136+ static HEX_DIGITS : & ' static [ u8 ; 16 ] = b"0123456789abcdef" ;
144137 let b3;
145138 let b4;
146- let bytes = if high > 0 {
147- let low = ascii_byte & 0x0F ;
148- b4 = [ b'\\' , to_hex_byte ( high) , to_hex_byte ( low) , b' ' ] ;
139+ let bytes = if ascii_byte > 0x0F {
140+ let high = ( ascii_byte >> 4 ) as usize ;
141+ let low = ( ascii_byte & 0x0F ) as usize ;
142+ b4 = [ b'\\' , HEX_DIGITS [ high] , HEX_DIGITS [ low] , b' ' ] ;
149143 & b4[ ..]
150144 } else {
151- b3 = [ b'\\' , to_hex_byte ( ascii_byte) , b' ' ] ;
145+ b3 = [ b'\\' , HEX_DIGITS [ ascii_byte as usize ] , b' ' ] ;
152146 & b3[ ..]
153147 } ;
154148 dest. write_str ( unsafe { str:: from_utf8_unchecked ( & bytes) } )
You can’t perform that action at this time.
0 commit comments