fix: add itoa dependency and optimize string formatting in Proxy implementation

This commit is contained in:
monosans
2025-12-24 13:31:29 +03:00
parent 843c9f3553
commit 44c1a8f177
4 changed files with 13 additions and 5 deletions
Generated
+1
View File
@@ -1415,6 +1415,7 @@ dependencies = [
"hickory-resolver",
"http",
"httpdate",
"itoa",
"log",
"maxminddb",
"mimalloc",
+1
View File
@@ -9,6 +9,7 @@ publish = false
async-trait = "=0.1.89"
color-eyre = "=0.6.5"
compact_str = { version = "=0.9.0", features = ["serde"] }
itoa = "=1.0.16"
crossterm = { version = "=0.28.1", default-features = false, features = [
"event-stream",
"windows",
+9 -4
View File
@@ -1,5 +1,4 @@
use std::{
fmt::Write as _,
hash::{Hash, Hasher},
str::FromStr,
sync::Arc,
@@ -139,16 +138,22 @@ impl Proxy {
let mut s = compact_str::CompactString::const_new("");
if include_protocol {
write!(s, "{}://", self.protocol.as_str()).unwrap();
s.push_str(self.protocol.as_str());
s.push_str("://");
}
if let (Some(username), Some(password)) =
(&self.username, &self.password)
{
write!(s, "{username}:{password}@").unwrap();
s.push_str(username);
s.push(':');
s.push_str(password);
s.push('@');
}
write!(s, "{}:{}", self.host, self.port).unwrap();
s.push_str(&self.host);
s.push(':');
s.push_str(itoa::Buffer::new().format(self.port));
s
}
+2 -1
View File
@@ -32,7 +32,8 @@ pub trait CompactStrJoin: Iterator {
);
write!(&mut result, "{first_elt}").unwrap();
for elt in self {
write!(&mut result, "{sep}{elt}").unwrap();
result.push_str(sep);
write!(&mut result, "{elt}").unwrap();
}
result
},