Skip to content

Commit

Permalink
Rename bytes to hex, allocate String with capacity.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcampbell24 committed Sep 28, 2024
1 parent ae01996 commit d338206
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/uucore/src/lib/features/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit d338206

Please sign in to comment.