From f2d0a18d67a93b225d520d39bf8b702af6e343b9 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 27 Jun 2024 14:44:50 -0400 Subject: [PATCH] kargs: Drop unnecessary `mut` and copying - Change filtering to use combinators which is a bit clearer I think - Rework to directly return the deserialized args from the toml file and avoid moving them into a new vector - Drop the now unnecessary `mut` Signed-off-by: Colin Walters --- lib/src/kargs.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/src/kargs.rs b/lib/src/kargs.rs index d71f48a0d..b03cff034 100644 --- a/lib/src/kargs.rs +++ b/lib/src/kargs.rs @@ -143,19 +143,15 @@ pub(crate) fn get_kargs( /// vector of kernel arguments. Architecture matching is performed using /// `sys_arch`. fn parse_kargs_toml(contents: &str, sys_arch: &str) -> Result> { - let mut de: Config = toml::from_str(contents)?; - let mut parsed_kargs: Vec = vec![]; + let de: Config = toml::from_str(contents)?; // if arch specified, apply kargs only if the arch matches // if arch not specified, apply kargs unconditionally - match de.match_architectures { - None => parsed_kargs = de.kargs, - Some(match_architectures) => { - if match_architectures.iter().any(|s| s == sys_arch) { - parsed_kargs.append(&mut de.kargs); - } - } - } - Ok(parsed_kargs) + let matched = de + .match_architectures + .map(|arches| arches.iter().any(|s| s == sys_arch)) + .unwrap_or(true); + let r = if matched { de.kargs } else { Vec::new() }; + Ok(r) } #[test]