Skip to content

Commit c3d5b2e

Browse files
fanquakeknst
authored andcommitted
partial Merge bitcoin#25872: Fix issues when calling std::move(const&)
BACKPORT NOTE: missing changes for TRDescriptor and for mempool_args fa87534 Fix iwyu (MacroFake) faad673 Fix issues when calling std::move(const&) (MacroFake) Pull request description: Passing a symbol to `std::move` that is marked `const` is a no-op, which can be fixed in two ways: * Remove the `const`, or * Remove the `std::move` ACKs for top commit: ryanofsky: Code review ACK fa87534. Looks good. Good for univalue to support c++11 move optimizations Tree-SHA512: 3dc5cad55b93cfa311abedfb811f35fc1b7f30a1c68561f15942438916c7de25e179c364be11881e01f844f9c2ccd71a3be55967ad5abd2f35b10bb7a882edea
1 parent 82a954f commit c3d5b2e

File tree

13 files changed

+26
-24
lines changed

13 files changed

+26
-24
lines changed

ci/dash/lint-tidy.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ iwyu_tool.py \
4444
"src/util/moneystr.cpp" \
4545
"src/util/serfloat.cpp" \
4646
"src/util/spanparsing.cpp" \
47+
"src/util/string.cpp" \
4748
"src/util/strencodings.cpp" \
4849
"src/util/syserror.cpp" \
4950
"src/util/url.cpp" \

src/.clang-tidy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ misc-unused-using-decls,
66
modernize-use-default-member-init,
77
modernize-use-nullptr,
88
performance-for-range-copy,
9+
performance-move-const-arg,
910
performance-unnecessary-copy-initialization,
1011
readability-const-return-type,
1112
readability-redundant-declaration,
@@ -18,7 +19,11 @@ misc-unused-using-decls,
1819
modernize-use-default-member-init,
1920
modernize-use-nullptr,
2021
performance-for-range-copy,
22+
performance-move-const-arg,
2123
performance-unnecessary-copy-initialization,
2224
readability-redundant-declaration,
2325
readability-redundant-string-init,
2426
'
27+
CheckOptions:
28+
- key: performance-move-const-arg.CheckTriviallyCopyableMove
29+
value: false

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2527,7 +2527,7 @@ static RPCHelpMan scantxoutset()
25272527
for (const UniValue& scanobject : request.params[1].get_array().getValues()) {
25282528
FlatSigningProvider provider;
25292529
auto scripts = EvalDescriptorStringOrObject(scanobject, provider);
2530-
for (const auto& script : scripts) {
2530+
for (CScript& script : scripts) {
25312531
std::string inferred = InferDescriptor(script, provider)->ToString();
25322532
needles.emplace(script);
25332533
descriptors.emplace(std::move(script), std::move(inferred));

src/script/descriptor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ class DescriptorImpl : public Descriptor
547547
if (pos++) ret += ",";
548548
std::string tmp;
549549
if (!scriptarg->ToStringHelper(arg, tmp, type, cache)) return false;
550-
ret += std::move(tmp);
550+
ret += tmp;
551551
}
552552
return true;
553553
}
@@ -571,7 +571,7 @@ class DescriptorImpl : public Descriptor
571571
tmp = pubkey->ToString();
572572
break;
573573
}
574-
ret += std::move(tmp);
574+
ret += tmp;
575575
}
576576
std::string subscript;
577577
if (!ToStringSubScriptHelper(arg, subscript, type, cache)) return false;

src/test/fuzz/txorphan.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <util/check.h>
2020
#include <util/time.h>
2121

22-
#include <algorithm>
2322
#include <cstdint>
2423
#include <memory>
2524
#include <set>

src/univalue/include/univalue.h

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

80-
void push_back(const UniValue& val);
80+
void push_back(UniValue val);
8181
void push_backV(const std::vector<UniValue>& vec);
8282
template <class It>
8383
void push_backV(It first, It last);
8484

85-
void __pushKV(const std::string& key, const UniValue& val);
86-
void pushKV(const std::string& key, const UniValue& val);
87-
void pushKVs(const UniValue& obj);
85+
void __pushKV(std::string key, UniValue val);
86+
void pushKV(std::string key, UniValue val);
87+
void pushKVs(UniValue obj);
8888

8989
std::string write(unsigned int prettyIndent = 0,
9090
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/message.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <key_io.h>
99
#include <pubkey.h>
1010
#include <script/standard.h>
11-
#include <serialize.h>
1211
#include <uint256.h>
1312
#include <util/message.h>
1413
#include <util/strencodings.h>

src/util/strencodings.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <span.h>
77
#include <util/strencodings.h>
88

9-
#include <algorithm>
109
#include <array>
1110
#include <cassert>
1211
#include <cstring>

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
}

0 commit comments

Comments
 (0)