Skip to content

Commit 3963067

Browse files
committed
Merge bitcoin/bitcoin#26642: clang-tidy: Add more performance-* checks and related fixes
03ec5b6 clang-tidy: Exclude `performance-*` checks rather including them (Hennadii Stepanov) 2400437 clang-tidy: Add `performance-type-promotion-in-math-fn` check (Hennadii Stepanov) 7e975e6 clang-tidy: Add `performance-inefficient-vector-operation` check (Hennadii Stepanov) 516b75f clang-tidy: Add `performance-faster-string-find` check (Hennadii Stepanov) Pull request description: ACKs for top commit: martinus: ACK 03ec5b6 TheCharlatan: re-ACK [03ec5b6](bitcoin/bitcoin@03ec5b6) Tree-SHA512: 2dfa52f9131da88826f32583bfd534a56a998477db9804b7333c0e7ac0b6b36141009755c7163b9f95d0ecbf5c2cb63f8a69ce4b114bb83423faed21b50cec67
2 parents 3e835ca + 03ec5b6 commit 3963067

25 files changed

+37
-14
lines changed

src/.clang-tidy

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ bugprone-use-after-move,
55
misc-unused-using-decls,
66
modernize-use-default-member-init,
77
modernize-use-nullptr,
8-
performance-for-range-copy,
9-
performance-move-const-arg,
10-
performance-no-automatic-move,
11-
performance-unnecessary-copy-initialization,
8+
performance-*,
9+
-performance-inefficient-string-concatenation,
10+
-performance-no-int-to-ptr,
11+
-performance-noexcept-move-constructor,
12+
-performance-unnecessary-value-param,
1213
readability-const-return-type,
1314
readability-redundant-declaration,
1415
readability-redundant-string-init,

src/bench/lockedpool.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ static void BenchLockedPool(benchmark::Bench& bench)
1717
const size_t synth_size = 1024*1024;
1818
Arena b(synth_base, synth_size, 16);
1919

20-
std::vector<void*> addr;
21-
for (int x=0; x<ASIZE; ++x)
22-
addr.push_back(nullptr);
20+
std::vector<void*> addr{ASIZE, nullptr};
2321
uint32_t s = 0x12345678;
2422
bench.run([&] {
2523
int idx = s & (addr.size() - 1);

src/bench/wallet_create_tx.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ static void AvailableCoins(benchmark::Bench& bench, const std::vector<OutputType
146146

147147
// Generate destinations
148148
std::vector<CScript> dest_wallet;
149+
dest_wallet.reserve(output_type.size());
149150
for (auto type : output_type) {
150151
dest_wallet.emplace_back(GetScriptForDestination(getNewDestination(wallet, type)));
151152
}

src/bitcoin-cli.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ static void ParseGetInfoResult(UniValue& result)
10321032
}
10331033

10341034
std::vector<std::string> formatted_proxies;
1035+
formatted_proxies.reserve(ordered_proxies.size());
10351036
for (const std::string& proxy : ordered_proxies) {
10361037
formatted_proxies.emplace_back(strprintf("%s (%s)", proxy, Join(proxy_networks.find(proxy)->second, ", ")));
10371038
}

src/bitcoin-util.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ static int Grind(const std::vector<std::string>& args, std::string& strPrint)
127127

128128
std::vector<std::thread> threads;
129129
int n_tasks = std::max(1u, std::thread::hardware_concurrency());
130+
threads.reserve(n_tasks);
130131
for (int i = 0; i < n_tasks; ++i) {
131132
threads.emplace_back(grind_task, nBits, header, i, n_tasks, std::ref(found), std::ref(proposed_nonce));
132133
}

src/node/interfaces.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ class NodeImpl : public Node
241241
if (command == "") return {};
242242
ExternalSigner::Enumerate(command, signers, Params().NetworkIDString());
243243
std::vector<std::unique_ptr<interfaces::ExternalSigner>> result;
244+
result.reserve(signers.size());
244245
for (auto& signer : signers) {
245246
result.emplace_back(std::make_unique<ExternalSignerImpl>(std::move(signer)));
246247
}

src/qt/trafficgraphwidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ void TrafficGraphWidget::paintEvent(QPaintEvent *)
6868
painter.drawLine(XMARGIN, YMARGIN + h, width() - XMARGIN, YMARGIN + h);
6969

7070
// decide what order of magnitude we are
71-
int base = floor(log10(fMax));
72-
float val = pow(10.0f, base);
71+
int base = std::floor(std::log10(fMax));
72+
float val = std::pow(10.0f, base);
7373

7474
const QString units = tr("kB/s");
7575
const float yMarginText = 2.0;

src/rpc/server.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest&
8383
std::string category;
8484
std::set<intptr_t> setDone;
8585
std::vector<std::pair<std::string, const CRPCCommand*> > vCommands;
86+
vCommands.reserve(mapCommands.size());
8687

8788
for (const auto& entry : mapCommands)
8889
vCommands.push_back(make_pair(entry.second.front()->category + entry.first, entry.second.front()));
@@ -513,6 +514,7 @@ static bool ExecuteCommand(const CRPCCommand& command, const JSONRPCRequest& req
513514
std::vector<std::string> CRPCTable::listCommands() const
514515
{
515516
std::vector<std::string> commandList;
517+
commandList.reserve(mapCommands.size());
516518
for (const auto& i : mapCommands) commandList.emplace_back(i.first);
517519
return commandList;
518520
}

src/rpc/util.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ bool RPCHelpMan::IsValidNumArgs(size_t num_args) const
608608
std::vector<std::string> RPCHelpMan::GetArgNames() const
609609
{
610610
std::vector<std::string> ret;
611+
ret.reserve(m_args.size());
611612
for (const auto& arg : m_args) {
612613
ret.emplace_back(arg.m_names);
613614
}
@@ -732,12 +733,12 @@ UniValue RPCArg::MatchesType(const UniValue& request) const
732733

733734
std::string RPCArg::GetFirstName() const
734735
{
735-
return m_names.substr(0, m_names.find("|"));
736+
return m_names.substr(0, m_names.find('|'));
736737
}
737738

738739
std::string RPCArg::GetName() const
739740
{
740-
CHECK_NONFATAL(std::string::npos == m_names.find("|"));
741+
CHECK_NONFATAL(std::string::npos == m_names.find('|'));
741742
return m_names;
742743
}
743744

src/script/descriptor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ class MultiADescriptor final : public DescriptorImpl
830830
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, Span<const CScript>, FlatSigningProvider&) const override {
831831
CScript ret;
832832
std::vector<XOnlyPubKey> xkeys;
833+
xkeys.reserve(keys.size());
833834
for (const auto& key : keys) xkeys.emplace_back(key);
834835
if (m_sorted) std::sort(xkeys.begin(), xkeys.end());
835836
ret << ToByteVector(xkeys[0]) << OP_CHECKSIG;

0 commit comments

Comments
 (0)