xmpp-parsers: Optimize to_hex() a bit
Just one correctly-sized String allocation, instead of one String per byte, a Vec<String>, and then a final String. skip-changelog: Internal change.
This commit is contained in:
parent
09640de5f2
commit
47c0edc3f6
1 changed files with 6 additions and 5 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
use alloc::borrow::Cow;
|
use alloc::borrow::Cow;
|
||||||
use core::{
|
use core::{
|
||||||
|
fmt::Write,
|
||||||
num::ParseIntError,
|
num::ParseIntError,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
|
|
@ -181,11 +182,11 @@ impl Hash {
|
||||||
|
|
||||||
/// Formats this hash into hexadecimal.
|
/// Formats this hash into hexadecimal.
|
||||||
pub fn to_hex(&self) -> String {
|
pub fn to_hex(&self) -> String {
|
||||||
self.hash
|
let mut hex = String::with_capacity(self.hash.len() * 2);
|
||||||
.iter()
|
for byte in &self.hash {
|
||||||
.map(|byte| format!("{:02x}", byte))
|
write!(&mut hex, "{:02x}", byte).unwrap();
|
||||||
.collect::<Vec<_>>()
|
}
|
||||||
.join("")
|
hex
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Formats this hash into colon-separated hexadecimal.
|
/// Formats this hash into colon-separated hexadecimal.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue