We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 10dccdc commit 8761424Copy full SHA for 8761424
library/core/src/ascii.rs
@@ -98,15 +98,23 @@ pub fn escape_default(c: u8) -> EscapeDefault {
98
b'\'' => ([b'\\', b'\'', 0, 0], 2),
99
b'"' => ([b'\\', b'"', 0, 0], 2),
100
b'\x20'..=b'\x7e' => ([c, 0, 0, 0], 1),
101
- _ => ([b'\\', b'x', hexify(c >> 4), hexify(c & 0xf)], 4),
+ _ => {
102
+ let (b1, b2) = hexify(c);
103
+ ([b'\\', b'x', b1, b2], 4)
104
+ }
105
};
106
107
return EscapeDefault { range: 0..len, data };
108
- fn hexify(b: u8) -> u8 {
- match b {
- 0..=9 => b'0' + b,
109
- _ => b'a' + b - 10,
+ #[inline]
110
+ fn hexify(b: u8) -> (u8, u8) {
111
+ let hex_digits: &[u8; 16] = b"0123456789abcdef";
112
+ // SAFETY: For all n: u8, n >> 4 < 16 and n & 0xf < 16
113
+ unsafe {
114
+ (
115
+ *hex_digits.get_unchecked((b >> 4) as usize),
116
+ *hex_digits.get_unchecked((b & 0xf) as usize),
117
+ )
118
}
119
120
0 commit comments