Skip to content

Commit

Permalink
kargs: Drop unnecessary mut and copying
Browse files Browse the repository at this point in the history
- 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]>
  • Loading branch information
cgwalters committed Jun 28, 2024
1 parent 04424a7 commit f2d0a18
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/src/kargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>> {
let mut de: Config = toml::from_str(contents)?;
let mut parsed_kargs: Vec<String> = 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]
Expand Down

0 comments on commit f2d0a18

Please sign in to comment.