From faad673716cfbad1e715f1bdf8ac00938a055aea Mon Sep 17 00:00:00 2001 From: MacroFake Date: Fri, 19 Aug 2022 11:38:56 +0200 Subject: Fix issues when calling std::move(const&) --- src/.clang-tidy | 5 +++++ src/rpc/blockchain.cpp | 2 +- src/script/descriptor.cpp | 6 +++--- src/univalue/include/univalue.h | 8 ++++---- src/univalue/lib/univalue.cpp | 20 ++++++++++---------- src/util/string.cpp | 3 +-- src/wallet/spend.cpp | 2 +- 7 files changed, 25 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/.clang-tidy b/src/.clang-tidy index f59f80f8ce..18f9035f07 100644 --- a/src/.clang-tidy +++ b/src/.clang-tidy @@ -5,6 +5,7 @@ misc-unused-using-decls, modernize-use-default-member-init, modernize-use-nullptr, performance-for-range-copy, +performance-move-const-arg, performance-unnecessary-copy-initialization, readability-redundant-declaration, readability-redundant-string-init, @@ -15,7 +16,11 @@ misc-unused-using-decls, modernize-use-default-member-init, modernize-use-nullptr, performance-for-range-copy, +performance-move-const-arg, performance-unnecessary-copy-initialization, readability-redundant-declaration, readability-redundant-string-init, ' +CheckOptions: + - key: performance-move-const-arg.CheckTriviallyCopyableMove + value: false diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 8f116a05ef..f57915e805 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -2129,7 +2129,7 @@ static RPCHelpMan scantxoutset() for (const UniValue& scanobject : request.params[1].get_array().getValues()) { FlatSigningProvider provider; auto scripts = EvalDescriptorStringOrObject(scanobject, provider); - for (const auto& script : scripts) { + for (CScript& script : scripts) { std::string inferred = InferDescriptor(script, provider)->ToString(); needles.emplace(script); descriptors.emplace(std::move(script), std::move(inferred)); diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index 434e106dad..93f6ec243c 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -572,7 +572,7 @@ public: if (pos++) ret += ","; std::string tmp; if (!scriptarg->ToStringHelper(arg, tmp, type, cache)) return false; - ret += std::move(tmp); + ret += tmp; } return true; } @@ -596,7 +596,7 @@ public: tmp = pubkey->ToString(); break; } - ret += std::move(tmp); + ret += tmp; } std::string subscript; if (!ToStringSubScriptHelper(arg, subscript, type, cache)) return false; @@ -912,7 +912,7 @@ protected: } std::string tmp; if (!m_subdescriptor_args[pos]->ToStringHelper(arg, tmp, type, cache)) return false; - ret += std::move(tmp); + ret += tmp; while (!path.empty() && path.back()) { if (path.size() > 1) ret += '}'; path.pop_back(); diff --git a/src/univalue/include/univalue.h b/src/univalue/include/univalue.h index 8ba6fd5425..ccaf56a271 100644 --- a/src/univalue/include/univalue.h +++ b/src/univalue/include/univalue.h @@ -80,14 +80,14 @@ public: bool isArray() const { return (typ == VARR); } bool isObject() const { return (typ == VOBJ); } - void push_back(const UniValue& val); + void push_back(UniValue val); void push_backV(const std::vector& vec); template void push_backV(It first, It last); - void __pushKV(const std::string& key, const UniValue& val); - void pushKV(const std::string& key, const UniValue& val); - void pushKVs(const UniValue& obj); + void __pushKV(std::string key, UniValue val); + void pushKV(std::string key, UniValue val); + void pushKVs(UniValue obj); std::string write(unsigned int prettyIndent = 0, unsigned int indentLevel = 0) const; diff --git a/src/univalue/lib/univalue.cpp b/src/univalue/lib/univalue.cpp index 55e777b8ae..12a434dd0e 100644 --- a/src/univalue/lib/univalue.cpp +++ b/src/univalue/lib/univalue.cpp @@ -101,11 +101,11 @@ void UniValue::setObject() typ = VOBJ; } -void UniValue::push_back(const UniValue& val_) +void UniValue::push_back(UniValue val) { checkType(VARR); - values.push_back(val_); + values.push_back(std::move(val)); } void UniValue::push_backV(const std::vector& vec) @@ -115,32 +115,32 @@ void UniValue::push_backV(const std::vector& vec) values.insert(values.end(), vec.begin(), vec.end()); } -void UniValue::__pushKV(const std::string& key, const UniValue& val_) +void UniValue::__pushKV(std::string key, UniValue val) { checkType(VOBJ); - keys.push_back(key); - values.push_back(val_); + keys.push_back(std::move(key)); + values.push_back(std::move(val)); } -void UniValue::pushKV(const std::string& key, const UniValue& val_) +void UniValue::pushKV(std::string key, UniValue val) { checkType(VOBJ); size_t idx; if (findKey(key, idx)) - values[idx] = val_; + values[idx] = std::move(val); else - __pushKV(key, val_); + __pushKV(std::move(key), std::move(val)); } -void UniValue::pushKVs(const UniValue& obj) +void UniValue::pushKVs(UniValue obj) { checkType(VOBJ); obj.checkType(VOBJ); for (size_t i = 0; i < obj.keys.size(); i++) - __pushKV(obj.keys[i], obj.values.at(i)); + __pushKV(std::move(obj.keys.at(i)), std::move(obj.values.at(i))); } void UniValue::getObjMap(std::map& kv) const diff --git a/src/util/string.cpp b/src/util/string.cpp index db6dbe4135..e994c85f1c 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -6,10 +6,9 @@ #include #include -#include void ReplaceAll(std::string& in_out, const std::string& search, const std::string& substitute) { if (search.empty()) return; - in_out = std::regex_replace(in_out, std::regex(std::move(search)), substitute); + in_out = std::regex_replace(in_out, std::regex(search), substitute); } diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 001acd04e2..d9b1eca020 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -353,7 +353,7 @@ std::map> ListCoins(const CWallet& wallet) std::map> result; - for (const COutput& coin : AvailableCoinsListUnspent(wallet).All()) { + for (COutput& coin : AvailableCoinsListUnspent(wallet).All()) { CTxDestination address; if ((coin.spendable || (wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && coin.solvable)) && ExtractDestination(FindNonChangeParentOutput(wallet, coin.outpoint).scriptPubKey, address)) { -- cgit v1.2.3 From fa875349e22f2f0f9c2c98ee991372d08ff90318 Mon Sep 17 00:00:00 2001 From: MacroFake Date: Fri, 19 Aug 2022 12:19:18 +0200 Subject: Fix iwyu --- src/node/mempool_args.cpp | 1 + src/test/fuzz/txorphan.cpp | 1 - src/threadinterrupt.h | 1 + src/util/bip32.cpp | 2 -- src/util/message.cpp | 1 - src/util/strencodings.cpp | 1 - src/util/string.h | 1 - 7 files changed, 2 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/node/mempool_args.cpp b/src/node/mempool_args.cpp index 60993f1d8d..d8b4ce4bf4 100644 --- a/src/node/mempool_args.cpp +++ b/src/node/mempool_args.cpp @@ -12,6 +12,7 @@ #include #include #include +#include