From d338206a6202e9b2442020e5795f6bdadb08dce5 Mon Sep 17 00:00:00 2001 From: David Campbell Date: Sat, 28 Sep 2024 16:09:41 -0400 Subject: [PATCH] Rename bytes to hex, allocate String with capacity. --- src/uucore/src/lib/features/checksum.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/uucore/src/lib/features/checksum.rs b/src/uucore/src/lib/features/checksum.rs index 1eb20397d..c55d56393 100644 --- a/src/uucore/src/lib/features/checksum.rs +++ b/src/uucore/src/lib/features/checksum.rs @@ -322,10 +322,12 @@ fn determine_regex(lines: &[String]) -> Option<(Regex, bool)> { // Converts bytes to a hexadecimal string fn bytes_to_hex(bytes: &[u8]) -> String { - bytes.iter().fold(String::new(), |mut bytes, byte| { - write!(bytes, "{byte:02x}").unwrap(); - bytes - }) + bytes + .iter() + .fold(String::with_capacity(bytes.len() * 2), |mut hex, byte| { + write!(hex, "{byte:02x}").unwrap(); + hex + }) } fn get_expected_checksum(