v0.34.0_4
This commit is contained in:
1 parent
f20c8da718
commit
5910e6e901
21 files changed
+377
-51
No files matched your search
@@ -13,12 +13,14 @@ fn request_id_hash(sequence: u64) -> String {
|
||||
|
||||
fn request_id_hex(digest: &[u8]) -> String {
|
||||
const HEX: &[u8; 16] = b"0123456789abcdef";
|
||||
let mut encoded = String::with_capacity(digest.len() * 2);
|
||||
for &byte in digest {
|
||||
encoded.push(HEX[(byte >> 4) as usize] as char);
|
||||
encoded.push(HEX[(byte & 0x0f) as usize] as char);
|
||||
// Encode two ASCII bytes per digest byte in one allocation; avoid 64
|
||||
// separate String::push bounds checks for the 32-byte SHA-256 digest.
|
||||
let mut encoded = vec![0u8; digest.len() * 2];
|
||||
for (i, &byte) in digest.iter().enumerate() {
|
||||
encoded[2 * i] = HEX[(byte >> 4) as usize];
|
||||
encoded[2 * i + 1] = HEX[(byte & 0x0f) as usize];
|
||||
}
|
||||
encoded
|
||||
String::from_utf8(encoded).expect("hex digits are always valid UTF-8")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in new issue
Block a user