Skip to content

Commit

Permalink
Merge bitcoin/bitcoin#31364: refactor: Fix remaining clang-tidy perfo…
Browse files Browse the repository at this point in the history
…rmance-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
  • Loading branch information
achow101 committed Nov 26, 2024
2 parents 5a4bc5c + 3305972 commit 733317b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/bench/sign_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static void SignTransactionSingleInput(benchmark::Bench& bench, InputType input_
bench.minEpochIterations(100).run([&] {
CMutableTransaction tx{unsigned_tx};
std::map<COutPoint, Coin> coins;
CScript prev_spk = prev_spks[(iter++) % prev_spks.size()];
const CScript& prev_spk = prev_spks[(iter++) % prev_spks.size()];
coins[prevout] = Coin(CTxOut(10000, prev_spk), /*nHeightIn=*/100, /*fCoinBaseIn=*/false);
std::map<int, bilingual_str> input_errors;
bool complete = SignTransaction(tx, &keystore, coins, SIGHASH_ALL, input_errors);
Expand Down
10 changes: 5 additions & 5 deletions src/bitcoin-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ static void MutateTxAddOutAddr(CMutableTransaction& tx, const std::string& strIn
CAmount value = ExtractAndValidateValue(vStrInputParts[0]);

// extract and validate ADDRESS
std::string strAddr = vStrInputParts[1];
const std::string& strAddr = vStrInputParts[1];
CTxDestination destination = DecodeDestination(strAddr);
if (!IsValidDestination(destination)) {
throw std::runtime_error("invalid TX output address");
Expand Down Expand Up @@ -337,7 +337,7 @@ static void MutateTxAddOutPubKey(CMutableTransaction& tx, const std::string& str
bool bSegWit = false;
bool bScriptHash = false;
if (vStrInputParts.size() == 3) {
std::string flags = vStrInputParts[2];
const std::string& flags = vStrInputParts[2];
bSegWit = (flags.find('W') != std::string::npos);
bScriptHash = (flags.find('S') != std::string::npos);
}
Expand Down Expand Up @@ -398,7 +398,7 @@ static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& s
bool bSegWit = false;
bool bScriptHash = false;
if (vStrInputParts.size() == numkeys + 4) {
std::string flags = vStrInputParts.back();
const std::string& flags = vStrInputParts.back();
bSegWit = (flags.find('W') != std::string::npos);
bScriptHash = (flags.find('S') != std::string::npos);
}
Expand Down Expand Up @@ -473,14 +473,14 @@ static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& str
CAmount value = ExtractAndValidateValue(vStrInputParts[0]);

// extract and validate script
std::string strScript = vStrInputParts[1];
const std::string& strScript = vStrInputParts[1];
CScript scriptPubKey = ParseScript(strScript);

// Extract FLAGS
bool bSegWit = false;
bool bScriptHash = false;
if (vStrInputParts.size() == 3) {
std::string flags = vStrInputParts.back();
const std::string& flags = vStrInputParts.back();
bSegWit = (flags.find('W') != std::string::npos);
bScriptHash = (flags.find('S') != std::string::npos);
}
Expand Down
2 changes: 1 addition & 1 deletion src/qt/bitcoinunits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ bool BitcoinUnits::parse(Unit unit, const QString& value, CAmount* val_out)
{
return false; // More than one dot
}
QString whole = parts[0];
const QString& whole = parts[0];
QString decimals;

if(parts.size() > 1)
Expand Down
2 changes: 1 addition & 1 deletion src/test/validation_block_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
bool ignored;
FastRandomContext insecure;
for (int i = 0; i < 1000; i++) {
auto block = blocks[insecure.randrange(blocks.size() - 1)];
const auto& block = blocks[insecure.randrange(blocks.size() - 1)];
Assert(m_node.chainman)->ProcessNewBlock(block, true, true, &ignored);
}

Expand Down

0 comments on commit 733317b

Please sign in to comment.