From f32f48b1193befdcaf257abe30f54d4ca09469e4 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 13 Mar 2025 11:32:07 +0100 Subject: [PATCH] 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 --- proxmox-router/src/cli/command.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/proxmox-router/src/cli/command.rs b/proxmox-router/src/cli/command.rs index 2ca2356a..7f5e7a09 100644 --- a/proxmox-router/src/cli/command.rs +++ b/proxmox-router/src/cli/command.rs @@ -314,13 +314,11 @@ pub(crate) fn replace_aliases( continue; } if old[..] == args[..old.len()] { - let new_args: Vec = 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; } }