Skip to content

Commit 5e1945b

Browse files
committed
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 <[email protected]>
1 parent dbd83bc commit 5e1945b

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

lib/src/kargs.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,15 @@ pub(crate) fn get_kargs(
143143
/// vector of kernel arguments. Architecture matching is performed using
144144
/// `sys_arch`.
145145
fn parse_kargs_toml(contents: &str, sys_arch: &str) -> Result<Vec<String>> {
146-
let mut de: Config = toml::from_str(contents)?;
147-
let mut parsed_kargs: Vec<String> = vec![];
146+
let de: Config = toml::from_str(contents)?;
148147
// if arch specified, apply kargs only if the arch matches
149148
// if arch not specified, apply kargs unconditionally
150-
match de.match_architectures {
151-
None => parsed_kargs = de.kargs,
152-
Some(match_architectures) => {
153-
if match_architectures.iter().any(|s| s == sys_arch) {
154-
parsed_kargs.append(&mut de.kargs);
155-
}
156-
}
157-
}
158-
Ok(parsed_kargs)
149+
let matched = de
150+
.match_architectures
151+
.map(|arches| arches.iter().any(|s| s == sys_arch))
152+
.unwrap_or(true);
153+
let r = if matched { de.kargs } else { Vec::new() };
154+
Ok(r)
159155
}
160156

161157
#[test]

0 commit comments

Comments
 (0)