From ca10a8726f2c777888f38fc267de845bfa7eab5d Mon Sep 17 00:00:00 2001 From: edef Date: Wed, 8 May 2024 06:10:03 +0000 Subject: fix(nix-compat/store_path): use Box We don't actually build up names in place here, so we don't need a capacity field. Saves 8 bytes. Change-Id: Icb01b45561e28fd525b726612f56d4640bc834c7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11604 Reviewed-by: flokli Tested-by: BuildkiteCI --- tvix/nix-compat/src/store_path/mod.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'tvix') diff --git a/tvix/nix-compat/src/store_path/mod.rs b/tvix/nix-compat/src/store_path/mod.rs index ff7ede77e1da..707c41a92d74 100644 --- a/tvix/nix-compat/src/store_path/mod.rs +++ b/tvix/nix-compat/src/store_path/mod.rs @@ -56,7 +56,7 @@ pub enum Error { #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct StorePath { digest: [u8; DIGEST_SIZE], - name: String, + name: Box, } impl StorePath { @@ -65,7 +65,7 @@ impl StorePath { } pub fn name(&self) -> &str { - self.name.as_ref() + &self.name } pub fn as_ref(&self) -> StorePathRef<'_> { @@ -176,10 +176,7 @@ pub struct StorePathRef<'a> { impl<'a> From<&'a StorePath> for StorePathRef<'a> { fn from(&StorePath { digest, ref name }: &'a StorePath) -> Self { - StorePathRef { - digest, - name: name.as_ref(), - } + StorePathRef { digest, name } } } @@ -209,7 +206,7 @@ impl<'a> StorePathRef<'a> { pub fn to_owned(&self) -> StorePath { StorePath { digest: self.digest, - name: self.name.to_owned(), + name: self.name.into(), } } @@ -394,7 +391,7 @@ mod tests { let expected_digest: [u8; DIGEST_SIZE] = hex!("8a12321522fd91efbd60ebb2481af88580f61600"); - assert_eq!("net-tools-1.60_p20170221182432", nixpath.name); + assert_eq!("net-tools-1.60_p20170221182432", nixpath.name()); assert_eq!(nixpath.digest, expected_digest); assert_eq!(example_nix_path_str, nixpath.to_string()) -- cgit 1.4.1