Skip to content

Commit

Permalink
Eliminate some unnecessary clones
Browse files Browse the repository at this point in the history
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 <deso@posteo.net>
  • Loading branch information
d-e-s-o authored and danobi committed Aug 27, 2024
1 parent 6c08afd commit 17b9fb6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,20 +669,20 @@ 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",
ROOTFS_9P_FS_MOUNT_TAG,
false,
));
c.args(kernel_args(
&kernel,
kernel,
&target.arch,
guest_init.as_path(),
target.kernel_args.as_ref(),
Expand Down Expand Up @@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions src/qga.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<Self> {
pub fn new(sock: &Path, has_kvm: bool) -> Result<Self> {
let timeout = if has_kvm {
KVM_TIMEOUT
} else {
Expand All @@ -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);
Expand Down

0 comments on commit 17b9fb6

Please sign in to comment.