From 659e00c4c1295a203c3d2018aa7a082de76feb80 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 18 Mar 2024 19:51:46 -0700 Subject: [PATCH] Use `Box` in Hashes to reduce size (#2536) --- crates/pypi-types/src/simple_json.rs | 24 ++++++++++++------------ crates/uv-client/src/html.rs | 8 ++++---- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/pypi-types/src/simple_json.rs b/crates/pypi-types/src/simple_json.rs index be39179e3..342d54b2b 100644 --- a/crates/pypi-types/src/simple_json.rs +++ b/crates/pypi-types/src/simple_json.rs @@ -143,10 +143,10 @@ impl Default for Yanked { #[archive(check_bytes)] #[archive_attr(derive(Debug))] pub struct Hashes { - pub md5: Option, - pub sha256: Option, - pub sha384: Option, - pub sha512: Option, + pub md5: Option>, + pub sha256: Option>, + pub sha384: Option>, + pub sha512: Option>, } impl Hashes { @@ -199,7 +199,7 @@ impl FromStr for Hashes { match name { "md5" => { - let md5 = value.to_string(); + let md5 = value.to_owned().into_boxed_str(); Ok(Hashes { md5: Some(md5), sha256: None, @@ -208,7 +208,7 @@ impl FromStr for Hashes { }) } "sha256" => { - let sha256 = value.to_string(); + let sha256 = value.to_owned().into_boxed_str(); Ok(Hashes { md5: None, sha256: Some(sha256), @@ -217,7 +217,7 @@ impl FromStr for Hashes { }) } "sha384" => { - let sha384 = value.to_string(); + let sha384 = value.to_owned().into_boxed_str(); Ok(Hashes { md5: None, sha256: None, @@ -226,7 +226,7 @@ impl FromStr for Hashes { }) } "sha512" => { - let sha512 = value.to_string(); + let sha512 = value.to_owned().into_boxed_str(); Ok(Hashes { md5: None, sha256: None, @@ -265,7 +265,7 @@ mod tests { sha256: None, sha384: None, sha512: Some( - "40627dcf047dadb22cd25ea7ecfe9cbf3bbbad0482ee5920b582f3809c97654f".to_string() + "40627dcf047dadb22cd25ea7ecfe9cbf3bbbad0482ee5920b582f3809c97654f".into() ), } ); @@ -278,7 +278,7 @@ mod tests { md5: None, sha256: None, sha384: Some( - "40627dcf047dadb22cd25ea7ecfe9cbf3bbbad0482ee5920b582f3809c97654f".to_string() + "40627dcf047dadb22cd25ea7ecfe9cbf3bbbad0482ee5920b582f3809c97654f".into() ), sha512: None } @@ -291,7 +291,7 @@ mod tests { Hashes { md5: None, sha256: Some( - "40627dcf047dadb22cd25ea7ecfe9cbf3bbbad0482ee5920b582f3809c97654f".to_string() + "40627dcf047dadb22cd25ea7ecfe9cbf3bbbad0482ee5920b582f3809c97654f".into() ), sha384: None, sha512: None @@ -304,7 +304,7 @@ mod tests { hashes, Hashes { md5: Some( - "090376d812fb6ac5f171e5938e82e7f2d7adc2b629101cec0db8b267815c85e2".to_string() + "090376d812fb6ac5f171e5938e82e7f2d7adc2b629101cec0db8b267815c85e2".into() ), sha256: None, sha384: None, diff --git a/crates/uv-client/src/html.rs b/crates/uv-client/src/html.rs index 299226adf..2bffce9b6 100644 --- a/crates/uv-client/src/html.rs +++ b/crates/uv-client/src/html.rs @@ -89,7 +89,7 @@ impl SimpleHtml { match name { "md5" => { let md5 = std::str::from_utf8(value.as_bytes())?; - let md5 = md5.to_string(); + let md5 = md5.to_owned().into_boxed_str(); Ok(Hashes { md5: Some(md5), sha256: None, @@ -99,7 +99,7 @@ impl SimpleHtml { } "sha256" => { let sha256 = std::str::from_utf8(value.as_bytes())?; - let sha256 = sha256.to_string(); + let sha256 = sha256.to_owned().into_boxed_str(); Ok(Hashes { md5: None, sha256: Some(sha256), @@ -109,7 +109,7 @@ impl SimpleHtml { } "sha384" => { let sha384 = std::str::from_utf8(value.as_bytes())?; - let sha384 = sha384.to_string(); + let sha384 = sha384.to_owned().into_boxed_str(); Ok(Hashes { md5: None, sha256: None, @@ -119,7 +119,7 @@ impl SimpleHtml { } "sha512" => { let sha512 = std::str::from_utf8(value.as_bytes())?; - let sha512 = sha512.to_string(); + let sha512 = sha512.to_owned().into_boxed_str(); Ok(Hashes { md5: None, sha256: None,