From 17b9fb645ad1152fb749ac9b5c56dcb7396f36f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Fri, 23 Aug 2024 15:23:50 -0700 Subject: [PATCH] Eliminate some unnecessary clones MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no need to clone if all we need is a reference. Remove some clones that are unnecessary. Signed-off-by: Daniel Müller --- src/qemu.rs | 10 +++++----- src/qga.rs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/qemu.rs b/src/qemu.rs index 66bf1cc..ceea26b 100644 --- a/src/qemu.rs +++ b/src/qemu.rs @@ -669,12 +669,12 @@ impl Qemu { .args(guest_agent_args(&qga_sock)) .args(virtio_serial_args(&command_sock)); // Always ensure the rootfs is first. - if let Some(image) = target.image.clone() { - c.args(drive_args(&image, 1)); + if let Some(image) = &target.image { + c.args(drive_args(image, 1)); if target.uefi { c.args(uefi_firmware_args(target.vm.bios.as_deref())); } - } else if let Some(kernel) = target.kernel.clone() { + } else if let Some(kernel) = &target.kernel { c.args(plan9_fs_args( target.rootfs.as_path(), "root", @@ -682,7 +682,7 @@ impl Qemu { false, )); c.args(kernel_args( - &kernel, + kernel, &target.arch, guest_init.as_path(), target.kernel_args.as_ref(), @@ -1038,7 +1038,7 @@ impl Qemu { debug!("QMP info: {:#?}", qmp_info); // Connect to QGA socket - let qga = QgaWrapper::new(self.qga_sock.clone(), host_supports_kvm(&self.arch)); + let qga = QgaWrapper::new(&self.qga_sock, host_supports_kvm(&self.arch)); let qga = match qga { Ok(q) => q, Err(e) => { diff --git a/src/qga.rs b/src/qga.rs index 374233b..79817f3 100644 --- a/src/qga.rs +++ b/src/qga.rs @@ -1,5 +1,5 @@ use std::os::unix::net::UnixStream; -use std::path::PathBuf; +use std::path::Path; use std::str::FromStr; use std::thread; use std::time::{Duration, Instant}; @@ -55,7 +55,7 @@ impl QgaWrapper { /// /// `sock` is the path to the QGA socket. /// `has_kvm` whether or not host supports KVM - pub fn new(sock: PathBuf, has_kvm: bool) -> Result { + pub fn new(sock: &Path, has_kvm: bool) -> Result { let timeout = if has_kvm { KVM_TIMEOUT } else { @@ -69,7 +69,7 @@ impl QgaWrapper { while Instant::now() < end { info!("Connecting to QGA ({i})"); i += 1; - let qga_stream = match UnixStream::connect(&sock) { + let qga_stream = match UnixStream::connect(sock) { Ok(s) => s, Err(e) => { error!("Failed to connect QGA, retrying: {}", e);