From 3a4fc4d7ab0f4f1ffb51ce396e627f468245e44b Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Wed, 16 Oct 2024 15:26:05 -0300 Subject: [PATCH] refactor: fix performance-move-const-arg lint errors --- .clang-tidy | 3 --- src/json-util.cpp | 2 +- src/jsonrpc-virtual-machine.cpp | 2 +- src/pma.cpp | 12 ++++++------ src/pma.h | 6 ++++++ src/virtio-net-carrier-slirp.cpp | 4 ++-- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index a503a1967..90f3dcf41 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -48,6 +48,3 @@ WarningsAsErrors: >- performance*, portability*, readability*, -CheckOptions: - - key: performance-move-const-arg.CheckTriviallyCopyableMove - value: 'false' diff --git a/src/json-util.cpp b/src/json-util.cpp index b7bfa3abe..025c4867e 100644 --- a/src/json-util.cpp +++ b/src/json-util.cpp @@ -1398,7 +1398,7 @@ void ju_get_opt_field(const nlohmann::json &j, const K &key, virtio_device_confi ju_get_opt_field(jhostfwd, "guest_ip"s, hostfwd.guest_ip, hostfwd_path); ju_get_opt_field(jhostfwd, "host_port"s, hostfwd.host_port, hostfwd_path); ju_get_opt_field(jhostfwd, "guest_port"s, hostfwd.guest_port, hostfwd_path); - net_user_config.hostfwd.emplace_back(std::move(hostfwd)); + net_user_config.hostfwd.emplace_back(hostfwd); } } value.emplace(std::move(net_user_config)); diff --git a/src/jsonrpc-virtual-machine.cpp b/src/jsonrpc-virtual-machine.cpp index 52308a3c0..ea85beae0 100644 --- a/src/jsonrpc-virtual-machine.cpp +++ b/src/jsonrpc-virtual-machine.cpp @@ -193,7 +193,7 @@ static std::string json_post(beast::tcp_stream &stream, const std::string &remot } // Return response body - return std::move(res.body().data()); + return res.body(); } catch (...) { // Close stream socket on errors beast::error_code ec; diff --git a/src/pma.cpp b/src/pma.cpp index ceff90deb..adea7e01f 100644 --- a/src/pma.cpp +++ b/src/pma.cpp @@ -44,9 +44,9 @@ pma_memory::~pma_memory() { } pma_memory::pma_memory(pma_memory &&other) noexcept : - m_length{std::move(other.m_length)}, - m_host_memory{std::move(other.m_host_memory)}, - m_mmapped{std::move(other.m_mmapped)} { + m_length{other.m_length}, + m_host_memory{other.m_host_memory}, + m_mmapped{other.m_mmapped} { // set other to safe state other.m_host_memory = nullptr; other.m_mmapped = false; @@ -122,9 +122,9 @@ pma_memory::pma_memory(const std::string &description, uint64_t length, const st pma_memory &pma_memory::operator=(pma_memory &&other) noexcept { release(); // copy from other - m_host_memory = std::move(other.m_host_memory); - m_mmapped = std::move(other.m_mmapped); - m_length = std::move(other.m_length); + m_host_memory = other.m_host_memory; + m_mmapped = other.m_mmapped; + m_length = other.m_length; // set other to safe state other.m_host_memory = nullptr; other.m_mmapped = false; diff --git a/src/pma.h b/src/pma.h index 47eda943c..b11c0afd0 100644 --- a/src/pma.h +++ b/src/pma.h @@ -66,6 +66,12 @@ class pma_device final { m_context{context} { (void) description; } + ~pma_device() = default; + + pma_device(const pma_device &other) = delete; + pma_device(pma_device &&other) = default; + pma_device &operator=(const pma_device &other) = delete; + pma_device &operator=(pma_device &&other) = default; /// \brief Returns context to pass to callbacks. void *get_context() { diff --git a/src/virtio-net-carrier-slirp.cpp b/src/virtio-net-carrier-slirp.cpp index 018c7d7a7..468d43593 100644 --- a/src/virtio-net-carrier-slirp.cpp +++ b/src/virtio-net-carrier-slirp.cpp @@ -91,7 +91,7 @@ static ssize_t slirp_send_packet(const void *buf, size_t len, void *opaque) { slirp_packet packet{len}; memcpy(packet.buf.data(), buf, len); try { - carrier->send_packets.emplace_back(std::move(packet)); + carrier->send_packets.emplace_back(packet); return static_cast(len); } catch (...) { #ifdef DEBUG_VIRTIO_ERRORS @@ -359,7 +359,7 @@ bool virtio_net_carrier_slirp::read_packet_from_host(i_device_state_access *a, v return true; } // Retrieve the next packet sent by slirp. - slirp_packet packet = std::move(send_packets.front()); + slirp_packet packet = send_packets.front(); send_packets.pop_front(); // Is there enough space in the write buffer to write this packet? if (VIRTIO_NET_ETHERNET_FRAME_OFFSET + packet.len > write_avail_len) {