From fd80292398082ceb63ddab96d92d74b29895b886 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 27 Jun 2024 13:42:15 -0400 Subject: [PATCH] kargs: Drop unnecessary cloning for sys_arch Since the function accepts a `&str`, drop the unnecessary cloning. Signed-off-by: Colin Walters --- lib/src/kargs.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/src/kargs.rs b/lib/src/kargs.rs index 4a96a02fc..9983b48b8 100644 --- a/lib/src/kargs.rs +++ b/lib/src/kargs.rs @@ -59,7 +59,7 @@ pub(crate) fn get_kargs( ) -> Result> { let cancellable = gio::Cancellable::NONE; let mut kargs: Vec = vec![]; - let sys_arch = std::env::consts::ARCH.to_string(); + let sys_arch = std::env::consts::ARCH; // Get the running kargs of the booted system if let Some(bootconfig) = ostree::Deployment::bootconfig(booted_deployment) { @@ -72,7 +72,7 @@ pub(crate) fn get_kargs( // Get the kargs in kargs.d of the booted system let root = &cap_std::fs::Dir::open_ambient_dir("/", cap_std::ambient_authority())?; - let mut existing_kargs: Vec = get_kargs_in_root(root, &sys_arch)?; + let mut existing_kargs: Vec = get_kargs_in_root(root, sys_arch)?; // Get the kargs in kargs.d of the pending image let mut remote_kargs: Vec = vec![]; @@ -107,7 +107,7 @@ pub(crate) fn get_kargs( ostree_ext::prelude::InputStreamExtManual::into_read(file_content.unwrap()); let s = std::io::read_to_string(&mut reader)?; let mut parsed_kargs = - parse_kargs_toml(&s, &sys_arch).with_context(|| format!("Parsing {name}"))?; + parse_kargs_toml(&s, sys_arch).with_context(|| format!("Parsing {name}"))?; remote_kargs.append(&mut parsed_kargs); } } @@ -161,39 +161,39 @@ fn parse_kargs_toml(contents: &str, sys_arch: &str) -> Result> { /// Verify that kargs are only applied to supported architectures fn test_arch() { // no arch specified, kargs ensure that kargs are applied unconditionally - let sys_arch = "x86_64".to_string(); + let sys_arch = "x86_64"; let file_content = r##"kargs = ["console=tty0", "nosmt"]"##.to_string(); - let parsed_kargs = parse_kargs_toml(&file_content, &sys_arch).unwrap(); + let parsed_kargs = parse_kargs_toml(&file_content, sys_arch).unwrap(); assert_eq!(parsed_kargs, ["console=tty0", "nosmt"]); - let sys_arch = "aarch64".to_string(); - let parsed_kargs = parse_kargs_toml(&file_content, &sys_arch).unwrap(); + let sys_arch = "aarch64"; + let parsed_kargs = parse_kargs_toml(&file_content, sys_arch).unwrap(); assert_eq!(parsed_kargs, ["console=tty0", "nosmt"]); // one arch matches and one doesn't, ensure that kargs are only applied for the matching arch - let sys_arch = "aarch64".to_string(); + let sys_arch = "aarch64"; let file_content = r##"kargs = ["console=tty0", "nosmt"] match-architectures = ["x86_64"] "## .to_string(); - let parsed_kargs = parse_kargs_toml(&file_content, &sys_arch).unwrap(); + let parsed_kargs = parse_kargs_toml(&file_content, sys_arch).unwrap(); assert_eq!(parsed_kargs, [] as [String; 0]); let file_content = r##"kargs = ["console=tty0", "nosmt"] match-architectures = ["aarch64"] "## .to_string(); - let parsed_kargs = parse_kargs_toml(&file_content, &sys_arch).unwrap(); + let parsed_kargs = parse_kargs_toml(&file_content, sys_arch).unwrap(); assert_eq!(parsed_kargs, ["console=tty0", "nosmt"]); // multiple arch specified, ensure that kargs are applied to both archs - let sys_arch = "x86_64".to_string(); + let sys_arch = "x86_64"; let file_content = r##"kargs = ["console=tty0", "nosmt"] match-architectures = ["x86_64", "aarch64"] "## .to_string(); - let parsed_kargs = parse_kargs_toml(&file_content, &sys_arch).unwrap(); + let parsed_kargs = parse_kargs_toml(&file_content, sys_arch).unwrap(); assert_eq!(parsed_kargs, ["console=tty0", "nosmt"]); std::env::set_var("ARCH", "aarch64"); - let parsed_kargs = parse_kargs_toml(&file_content, &sys_arch).unwrap(); + let parsed_kargs = parse_kargs_toml(&file_content, sys_arch).unwrap(); assert_eq!(parsed_kargs, ["console=tty0", "nosmt"]); }