Skip to content

Commit faad673

Browse files
author
MacroFake
committed
Fix issues when calling std::move(const&)
1 parent c73c8d5 commit faad673

File tree

7 files changed

+25
-21
lines changed

7 files changed

+25
-21
lines changed

src/.clang-tidy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ misc-unused-using-decls,
55
modernize-use-default-member-init,
66
modernize-use-nullptr,
77
performance-for-range-copy,
8+
performance-move-const-arg,
89
performance-unnecessary-copy-initialization,
910
readability-redundant-declaration,
1011
readability-redundant-string-init,
@@ -15,7 +16,11 @@ misc-unused-using-decls,
1516
modernize-use-default-member-init,
1617
modernize-use-nullptr,
1718
performance-for-range-copy,
19+
performance-move-const-arg,
1820
performance-unnecessary-copy-initialization,
1921
readability-redundant-declaration,
2022
readability-redundant-string-init,
2123
'
24+
CheckOptions:
25+
- key: performance-move-const-arg.CheckTriviallyCopyableMove
26+
value: false

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,7 @@ static RPCHelpMan scantxoutset()
21292129
for (const UniValue& scanobject : request.params[1].get_array().getValues()) {
21302130
FlatSigningProvider provider;
21312131
auto scripts = EvalDescriptorStringOrObject(scanobject, provider);
2132-
for (const auto& script : scripts) {
2132+
for (CScript& script : scripts) {
21332133
std::string inferred = InferDescriptor(script, provider)->ToString();
21342134
needles.emplace(script);
21352135
descriptors.emplace(std::move(script), std::move(inferred));

src/script/descriptor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ class DescriptorImpl : public Descriptor
572572
if (pos++) ret += ",";
573573
std::string tmp;
574574
if (!scriptarg->ToStringHelper(arg, tmp, type, cache)) return false;
575-
ret += std::move(tmp);
575+
ret += tmp;
576576
}
577577
return true;
578578
}
@@ -596,7 +596,7 @@ class DescriptorImpl : public Descriptor
596596
tmp = pubkey->ToString();
597597
break;
598598
}
599-
ret += std::move(tmp);
599+
ret += tmp;
600600
}
601601
std::string subscript;
602602
if (!ToStringSubScriptHelper(arg, subscript, type, cache)) return false;
@@ -912,7 +912,7 @@ class TRDescriptor final : public DescriptorImpl
912912
}
913913
std::string tmp;
914914
if (!m_subdescriptor_args[pos]->ToStringHelper(arg, tmp, type, cache)) return false;
915-
ret += std::move(tmp);
915+
ret += tmp;
916916
while (!path.empty() && path.back()) {
917917
if (path.size() > 1) ret += '}';
918918
path.pop_back();

src/univalue/include/univalue.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ class UniValue {
8080
bool isArray() const { return (typ == VARR); }
8181
bool isObject() const { return (typ == VOBJ); }
8282

83-
void push_back(const UniValue& val);
83+
void push_back(UniValue val);
8484
void push_backV(const std::vector<UniValue>& vec);
8585
template <class It>
8686
void push_backV(It first, It last);
8787

88-
void __pushKV(const std::string& key, const UniValue& val);
89-
void pushKV(const std::string& key, const UniValue& val);
90-
void pushKVs(const UniValue& obj);
88+
void __pushKV(std::string key, UniValue val);
89+
void pushKV(std::string key, UniValue val);
90+
void pushKVs(UniValue obj);
9191

9292
std::string write(unsigned int prettyIndent = 0,
9393
unsigned int indentLevel = 0) const;

src/univalue/lib/univalue.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ void UniValue::setObject()
101101
typ = VOBJ;
102102
}
103103

104-
void UniValue::push_back(const UniValue& val_)
104+
void UniValue::push_back(UniValue val)
105105
{
106106
checkType(VARR);
107107

108-
values.push_back(val_);
108+
values.push_back(std::move(val));
109109
}
110110

111111
void UniValue::push_backV(const std::vector<UniValue>& vec)
@@ -115,32 +115,32 @@ void UniValue::push_backV(const std::vector<UniValue>& vec)
115115
values.insert(values.end(), vec.begin(), vec.end());
116116
}
117117

118-
void UniValue::__pushKV(const std::string& key, const UniValue& val_)
118+
void UniValue::__pushKV(std::string key, UniValue val)
119119
{
120120
checkType(VOBJ);
121121

122-
keys.push_back(key);
123-
values.push_back(val_);
122+
keys.push_back(std::move(key));
123+
values.push_back(std::move(val));
124124
}
125125

126-
void UniValue::pushKV(const std::string& key, const UniValue& val_)
126+
void UniValue::pushKV(std::string key, UniValue val)
127127
{
128128
checkType(VOBJ);
129129

130130
size_t idx;
131131
if (findKey(key, idx))
132-
values[idx] = val_;
132+
values[idx] = std::move(val);
133133
else
134-
__pushKV(key, val_);
134+
__pushKV(std::move(key), std::move(val));
135135
}
136136

137-
void UniValue::pushKVs(const UniValue& obj)
137+
void UniValue::pushKVs(UniValue obj)
138138
{
139139
checkType(VOBJ);
140140
obj.checkType(VOBJ);
141141

142142
for (size_t i = 0; i < obj.keys.size(); i++)
143-
__pushKV(obj.keys[i], obj.values.at(i));
143+
__pushKV(std::move(obj.keys.at(i)), std::move(obj.values.at(i)));
144144
}
145145

146146
void UniValue::getObjMap(std::map<std::string,UniValue>& kv) const

src/util/string.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66

77
#include <regex>
88
#include <string>
9-
#include <utility>
109

1110
void ReplaceAll(std::string& in_out, const std::string& search, const std::string& substitute)
1211
{
1312
if (search.empty()) return;
14-
in_out = std::regex_replace(in_out, std::regex(std::move(search)), substitute);
13+
in_out = std::regex_replace(in_out, std::regex(search), substitute);
1514
}

src/wallet/spend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet& wallet)
353353

354354
std::map<CTxDestination, std::vector<COutput>> result;
355355

356-
for (const COutput& coin : AvailableCoinsListUnspent(wallet).All()) {
356+
for (COutput& coin : AvailableCoinsListUnspent(wallet).All()) {
357357
CTxDestination address;
358358
if ((coin.spendable || (wallet.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && coin.solvable)) &&
359359
ExtractDestination(FindNonChangeParentOutput(wallet, coin.outpoint).scriptPubKey, address)) {

0 commit comments

Comments
 (0)