router: cli: avoid unnecessary clones/allocation

The `new_args` Vec is directly passed to the other Vec's `.extend()`,
which takes an `IntoIterator` consuming it, so just pass the
intermediate `Iterator`.

The `rest` Vec owns its strings and we don't need it afterwards, so
similarly, we can consume it via `.extend()` instead of a manual
push(s.clone()) loop.

The .truncate(0) can just be .clear() - they are equivalent according
to their documentation.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2025-03-13 11:32:07 +01:00
parent 00c75c734d
commit f32f48b119

View File

@ -314,13 +314,11 @@ pub(crate) fn replace_aliases(
continue;
}
if old[..] == args[..old.len()] {
let new_args: Vec<String> = new.iter().map(|s| String::from(*s)).collect();
let new_args = new.iter().map(|s| String::from(*s));
let rest = args.split_off(old.len());
args.truncate(0);
args.clear();
args.extend(new_args);
for arg in rest.iter() {
args.push(arg.clone());
}
args.extend(rest);
return;
}
}