Skip to content

Commit 733317b

Browse files
committed
Merge bitcoin/bitcoin#31364: refactor: Fix remaining clang-tidy performance-unnecessary-copy-initialization errors
3305972 refactor: Fix remaining clang-tidy performance-unnecessary-copy-initialization errors (Lőrinc) Pull request description: A follow-up of bitcoin/bitcoin#31305. The `clang-tidy` check can be run via: ```bash cmake -B build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBUILD_BENCH=ON -DBUILD_FUZZ_BINARY=ON -DBUILD_FOR_FUZZING=ON && cmake --build build -j$(nproc) run-clang-tidy -quiet -p build -j $(nproc) -checks='-*,performance-unnecessary-copy-initialization' | grep -v 'clang-tidy' ``` ACKs for top commit: maflcko: review ACK 3305972 🏀 achow101: ACK 3305972 theuni: ACK the much more constrained 3305972. hebasto: ACK 3305972, tested with clang 19.1.5 + clang-tidy. Tree-SHA512: 64dc3b35f33b7ac064ebf9e56e9f0ceca5d26681a1379dcd2168987960020fe1a282ec4de8c353c82ddf0a534a4866b607fc691e690010c6cea78887045897fb
2 parents 5a4bc5c + 3305972 commit 733317b

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/bench/sign_transaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static void SignTransactionSingleInput(benchmark::Bench& bench, InputType input_
6262
bench.minEpochIterations(100).run([&] {
6363
CMutableTransaction tx{unsigned_tx};
6464
std::map<COutPoint, Coin> coins;
65-
CScript prev_spk = prev_spks[(iter++) % prev_spks.size()];
65+
const CScript& prev_spk = prev_spks[(iter++) % prev_spks.size()];
6666
coins[prevout] = Coin(CTxOut(10000, prev_spk), /*nHeightIn=*/100, /*fCoinBaseIn=*/false);
6767
std::map<int, bilingual_str> input_errors;
6868
bool complete = SignTransaction(tx, &keystore, coins, SIGHASH_ALL, input_errors);

src/bitcoin-tx.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ static void MutateTxAddOutAddr(CMutableTransaction& tx, const std::string& strIn
304304
CAmount value = ExtractAndValidateValue(vStrInputParts[0]);
305305

306306
// extract and validate ADDRESS
307-
std::string strAddr = vStrInputParts[1];
307+
const std::string& strAddr = vStrInputParts[1];
308308
CTxDestination destination = DecodeDestination(strAddr);
309309
if (!IsValidDestination(destination)) {
310310
throw std::runtime_error("invalid TX output address");
@@ -337,7 +337,7 @@ static void MutateTxAddOutPubKey(CMutableTransaction& tx, const std::string& str
337337
bool bSegWit = false;
338338
bool bScriptHash = false;
339339
if (vStrInputParts.size() == 3) {
340-
std::string flags = vStrInputParts[2];
340+
const std::string& flags = vStrInputParts[2];
341341
bSegWit = (flags.find('W') != std::string::npos);
342342
bScriptHash = (flags.find('S') != std::string::npos);
343343
}
@@ -398,7 +398,7 @@ static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& s
398398
bool bSegWit = false;
399399
bool bScriptHash = false;
400400
if (vStrInputParts.size() == numkeys + 4) {
401-
std::string flags = vStrInputParts.back();
401+
const std::string& flags = vStrInputParts.back();
402402
bSegWit = (flags.find('W') != std::string::npos);
403403
bScriptHash = (flags.find('S') != std::string::npos);
404404
}
@@ -473,14 +473,14 @@ static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& str
473473
CAmount value = ExtractAndValidateValue(vStrInputParts[0]);
474474

475475
// extract and validate script
476-
std::string strScript = vStrInputParts[1];
476+
const std::string& strScript = vStrInputParts[1];
477477
CScript scriptPubKey = ParseScript(strScript);
478478

479479
// Extract FLAGS
480480
bool bSegWit = false;
481481
bool bScriptHash = false;
482482
if (vStrInputParts.size() == 3) {
483-
std::string flags = vStrInputParts.back();
483+
const std::string& flags = vStrInputParts.back();
484484
bSegWit = (flags.find('W') != std::string::npos);
485485
bScriptHash = (flags.find('S') != std::string::npos);
486486
}

src/qt/bitcoinunits.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ bool BitcoinUnits::parse(Unit unit, const QString& value, CAmount* val_out)
166166
{
167167
return false; // More than one dot
168168
}
169-
QString whole = parts[0];
169+
const QString& whole = parts[0];
170170
QString decimals;
171171

172172
if(parts.size() > 1)

src/test/validation_block_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
181181
bool ignored;
182182
FastRandomContext insecure;
183183
for (int i = 0; i < 1000; i++) {
184-
auto block = blocks[insecure.randrange(blocks.size() - 1)];
184+
const auto& block = blocks[insecure.randrange(blocks.size() - 1)];
185185
Assert(m_node.chainman)->ProcessNewBlock(block, true, true, &ignored);
186186
}
187187

0 commit comments

Comments
 (0)