X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=library%2Fcore%2Fsrc%2Fascii.rs;h=8a4cb78cc7f92f5a2fabedad3f3342389d7b3b48;hb=637592d8c3d07aeb2a204402fe250c6a763aa452;hp=532208e41afa2ba2b01169da64c061d0d5587347;hpb=78ae132d5b87c9f7e1ea51d1585646da1958257f;p=rust.git diff --git a/library/core/src/ascii.rs b/library/core/src/ascii.rs index 532208e41af..8a4cb78cc7f 100644 --- a/library/core/src/ascii.rs +++ b/library/core/src/ascii.rs @@ -98,22 +98,20 @@ pub fn escape_default(c: u8) -> EscapeDefault { b'\'' => ([b'\\', b'\'', 0, 0], 2), b'"' => ([b'\\', b'"', 0, 0], 2), b'\x20'..=b'\x7e' => ([c, 0, 0, 0], 1), - _ => ([b'\\', b'x', hexify(c >> 4), hexify(c & 0xf)], 4), + _ => { + let hex_digits: &[u8; 16] = b"0123456789abcdef"; + ([b'\\', b'x', hex_digits[(c >> 4) as usize], hex_digits[(c & 0xf) as usize]], 4) + } }; return EscapeDefault { range: 0..len, data }; - - fn hexify(b: u8) -> u8 { - match b { - 0..=9 => b'0' + b, - _ => b'a' + b - 10, - } - } } #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for EscapeDefault { type Item = u8; + + #[inline] fn next(&mut self) -> Option { self.range.next().map(|i| self.data[i as usize]) }