From 53996d69119fe749416f6f8fa56eff6b0a59c975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Kubern=C3=A1t?= Date: Mon, 25 Nov 2024 16:35:08 +0100 Subject: [PATCH] Avoid a few unneeded copies --- libshvbroker/src/brokeraclnode.cpp | 3 +-- libshvbroker/src/brokerapp.cpp | 2 +- libshvchainpack/tests/test_chainpack.cpp | 2 +- libshvcore/src/utils/shvtypeinfo.cpp | 3 +-- libshviotqt/src/node/shvnode.cpp | 2 +- libshviotqt/tests/test_frame_reader.cpp | 10 +++++----- libshvvisu/src/timeline/channelfiltermodel.cpp | 2 +- 7 files changed, 11 insertions(+), 13 deletions(-) diff --git a/libshvbroker/src/brokeraclnode.cpp b/libshvbroker/src/brokeraclnode.cpp index a4977f641..56858f826 100644 --- a/libshvbroker/src/brokeraclnode.cpp +++ b/libshvbroker/src/brokeraclnode.cpp @@ -273,8 +273,7 @@ chainpack::RpcValue RolesAclNode::callMethod(const iotqt::node::ShvNode::StringV if(shv_path.empty()) { if(method == M_SET_VALUE) { if(params.isList()) { - const auto p = params; - const auto &lst = p.asList(); + const auto &lst = params.asList(); const std::string role_name = lst.value(0).asString(); chainpack::RpcValue rv = lst.value(1); diff --git a/libshvbroker/src/brokerapp.cpp b/libshvbroker/src/brokerapp.cpp index 2fb15f26e..17e164ffa 100644 --- a/libshvbroker/src/brokerapp.cpp +++ b/libshvbroker/src/brokerapp.cpp @@ -260,7 +260,7 @@ auto transform_cli_group_mapping(const chainpack::RpcList& cli_group_mapping) cli_group_mapping.end(), std::back_inserter(group_mapping), [] (const auto& mapping) { - auto mapping_list = mapping.asList(); + const auto& mapping_list = mapping.asList(); if (mapping_list.size() != 2) { #ifdef _MSC_VER SHV_EXCEPTION(__FUNCSIG__ + std::string{": group mapping isn't a pair."}); diff --git a/libshvchainpack/tests/test_chainpack.cpp b/libshvchainpack/tests/test_chainpack.cpp index 9259ebda6..f19783849 100644 --- a/libshvchainpack/tests/test_chainpack.cpp +++ b/libshvchainpack/tests/test_chainpack.cpp @@ -344,7 +344,7 @@ DOCTEST_TEST_CASE("ChainPack") } ChainPackReader rd(out); RpcValue cp2 = rd.read(); nDebug() << cp2.toCpon() << " dump: " << binary_dump(out.str()).c_str(); - const RpcList list = cp2.asList(); + const RpcList& list = cp2.asList(); REQUIRE(list.size() == N); for (size_t i = 0; i < list.size(); ++i) { std::string s("foo-bar"); diff --git a/libshvcore/src/utils/shvtypeinfo.cpp b/libshvcore/src/utils/shvtypeinfo.cpp index 994988b1e..a0453aa50 100644 --- a/libshvcore/src/utils/shvtypeinfo.cpp +++ b/libshvcore/src/utils/shvtypeinfo.cpp @@ -579,11 +579,10 @@ ShvPropertyDescr &ShvPropertyDescr::addMethod(const ShvMethodDescr &method_descr ShvPropertyDescr &ShvPropertyDescr::setMethod(const ShvMethodDescr &method_descr) { - auto name = method_descr.name(); auto method_list = methods(); bool method_found = false; for(auto &mm : method_list) { - if(mm.name() == name) { + if(mm.name() == method_descr.name()) { mm = method_descr; method_found = true; break; diff --git a/libshviotqt/src/node/shvnode.cpp b/libshviotqt/src/node/shvnode.cpp index 4951b1835..549f8aa87 100644 --- a/libshviotqt/src/node/shvnode.cpp +++ b/libshviotqt/src/node/shvnode.cpp @@ -393,7 +393,7 @@ void ShvNode::treeWalk_helper(std::function msg_to_raw_data_serial(const vector &cpons, SerialFrameWr void test_valid_data(FrameReader *rd, const vector &data) { - auto rq1 = data[0]; - auto rs1 = data[1]; - auto rs2 = data[2]; - auto sig1 = data[3]; + const auto& rq1 = data[0]; + const auto& rs1 = data[1]; + const auto& rs2 = data[2]; + const auto& sig1 = data[3]; { auto ret = rd->addData(rq1); REQUIRE(ret.isEmpty()); @@ -96,7 +96,7 @@ void test_valid_data(FrameReader *rd, const vector &data) void test_incomplete_data(FrameReader *rd, const vector &data) { - auto rs1 = data[1]; + const auto& rs1 = data[1]; vector chunks; vector ixs = {0, 4, rs1.size() - 2, rs1.size()}; for (size_t i = 1; i < ixs.size(); i++) { diff --git a/libshvvisu/src/timeline/channelfiltermodel.cpp b/libshvvisu/src/timeline/channelfiltermodel.cpp index e7936c2d4..b2522ff4c 100644 --- a/libshvvisu/src/timeline/channelfiltermodel.cpp +++ b/libshvvisu/src/timeline/channelfiltermodel.cpp @@ -183,7 +183,7 @@ void ChannelFilterModel::createNodesForPath(const QString &path, const QMapsetData(dir_name, UserData::DirName);