Skip to content

Commit

Permalink
avoid or delay str heap allocation for str-sourced deserializers
Browse files Browse the repository at this point in the history
  • Loading branch information
GlenDC committed Dec 30, 2024
1 parent 620d182 commit 1e2acae
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions rama-net/src/address/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ impl<'de> serde::Deserialize<'de> for Authority {
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
s.try_into().map_err(serde::de::Error::custom)
let s = <&'de str>::deserialize(deserializer)?;
s.parse().map_err(serde::de::Error::custom)
}
}

Expand Down
4 changes: 2 additions & 2 deletions rama-net/src/address/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ impl<'de> serde::Deserialize<'de> for Domain {
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
s.try_into().map_err(serde::de::Error::custom)
let s = <&'de str>::deserialize(deserializer)?;
s.parse().map_err(serde::de::Error::custom)
}
}

Expand Down
4 changes: 2 additions & 2 deletions rama-net/src/address/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ impl<'de> serde::Deserialize<'de> for Host {
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
s.try_into().map_err(serde::de::Error::custom)
let s = <&'de str>::deserialize(deserializer)?;
s.parse().map_err(serde::de::Error::custom)
}
}

Expand Down
4 changes: 2 additions & 2 deletions rama-net/src/address/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ impl<'de> serde::Deserialize<'de> for ProxyAddress {
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
s.try_into().map_err(serde::de::Error::custom)
let s = <&'de str>::deserialize(deserializer)?;
s.parse().map_err(serde::de::Error::custom)
}
}

Expand Down
4 changes: 2 additions & 2 deletions rama-net/src/address/socket_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ impl<'de> serde::Deserialize<'de> for SocketAddress {
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
s.try_into().map_err(serde::de::Error::custom)
let s = <&'de str>::deserialize(deserializer)?;
s.parse().map_err(serde::de::Error::custom)
}
}

Expand Down
4 changes: 2 additions & 2 deletions rama-net/src/forwarded/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ impl<'de> serde::Deserialize<'de> for NodeId {
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
s.try_into().map_err(serde::de::Error::custom)
let s = <&'de str>::deserialize(deserializer)?;
s.parse().map_err(serde::de::Error::custom)
}
}

Expand Down
4 changes: 2 additions & 2 deletions rama-net/src/forwarded/obfuscated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ macro_rules! create_obf_type {
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
s.try_into().map_err(serde::de::Error::custom)
let s = <&'de str>::deserialize(deserializer)?;
s.parse().map_err(serde::de::Error::custom)
}
}
};
Expand Down
8 changes: 4 additions & 4 deletions rama-ua/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ impl<'de> Deserialize<'de> for HttpAgent {
where
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
let s = <&'de str>::deserialize(deserializer)?;
match_ignore_ascii_case_str! {
match (s.as_str()) {
match (s) {
"chrome" | "chromium" => Ok(HttpAgent::Chromium),
"Firefox" => Ok(HttpAgent::Firefox),
"Safari" => Ok(HttpAgent::Safari),
Expand Down Expand Up @@ -358,9 +358,9 @@ impl<'de> Deserialize<'de> for TlsAgent {
where
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
let s = <&'de str>::deserialize(deserializer)?;
match_ignore_ascii_case_str! {
match (s.as_str()) {
match (s) {
"rustls" => Ok(TlsAgent::Rustls),
"boring" | "boringssl" => Ok(TlsAgent::Boringssl),
"nss" => Ok(TlsAgent::Nss),
Expand Down
4 changes: 2 additions & 2 deletions rama-utils/src/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ impl<'de> serde::Deserialize<'de> for NonEmptyString {
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
s.try_into().map_err(serde::de::Error::custom)
let s = <&'de str>::deserialize(deserializer)?;
s.parse().map_err(serde::de::Error::custom)
}
}

Expand Down

0 comments on commit 1e2acae

Please sign in to comment.