From 4791d16a8efc42fb40ffab79bcdae4f0e106cd89 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Thu, 7 Mar 2024 10:00:43 -0700 Subject: perf(cli): use faster_hex (#22761) `cli::util::checksum` was showing up on flame graphs because it was concatenating allocated strings. We can use `faster-hex` to improve it. --- cli/util/checksum.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'cli/util') diff --git a/cli/util/checksum.rs b/cli/util/checksum.rs index d9480eb6e..c9c55ec2b 100644 --- a/cli/util/checksum.rs +++ b/cli/util/checksum.rs @@ -3,18 +3,13 @@ use ring::digest::Context; use ring::digest::SHA256; +/// Generate a SHA256 checksum of a slice of byte-slice-like things. pub fn gen(v: &[impl AsRef<[u8]>]) -> String { let mut ctx = Context::new(&SHA256); for src in v { ctx.update(src.as_ref()); } - let digest = ctx.finish(); - let out: Vec = digest - .as_ref() - .iter() - .map(|byte| format!("{byte:02x}")) - .collect(); - out.join("") + faster_hex::hex_string(ctx.finish().as_ref()) } #[cfg(test)] -- cgit v1.2.3