Skip to content

Commit 08ea835

Browse files
committed
Merge bitcoin/bitcoin#28583: refactor: [tidy] modernize-use-emplace
fa05a72 tidy: modernize-use-emplace (MarcoFalke) Pull request description: Constructing a temporary unnamed object only to copy or move it into a container seems both verbose in code and a strict performance penalty. Fix both issues via the `modernize-use-emplace` tidy check. ACKs for top commit: Sjors: re-utACK fa05a72 hebasto: ACK fa05a72. TheCharlatan: ACK fa05a72 Tree-SHA512: 4408a094f406e7bf6c1468c2b0798f68f4d952a1253cf5b20bdc648ad7eea4a2c070051fed46d66fd37bce2ce6f85962484a1d32826b7ab8c9baba431eaa2765
2 parents 9270453 + fa05a72 commit 08ea835

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+167
-162
lines changed

src/.bear-tidy-config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"src/crypto/ctaes",
99
"src/leveldb",
1010
"src/minisketch",
11+
"src/bench/nanobench.cpp",
12+
"src/bench/nanobench.h",
1113
"src/secp256k1"
1214
]
1315
},

src/.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ bugprone-argument-comment,
55
bugprone-use-after-move,
66
misc-unused-using-decls,
77
modernize-use-default-member-init,
8+
modernize-use-emplace,
89
modernize-use-noexcept,
910
modernize-use-nullptr,
1011
performance-*,

src/addrman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ std::vector<std::pair<AddrInfo, AddressPosition>> AddrManImpl::GetEntries_(bool
854854
/*multiplicity_in=*/from_tried ? 1 : info.nRefCount,
855855
bucket,
856856
position);
857-
infos.push_back(std::make_pair(info, location));
857+
infos.emplace_back(info, location);
858858
}
859859
}
860860
}

src/bench/block_assemble.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static void AssembleBlock(benchmark::Bench& bench)
2828
std::array<CTransactionRef, NUM_BLOCKS - COINBASE_MATURITY + 1> txs;
2929
for (size_t b{0}; b < NUM_BLOCKS; ++b) {
3030
CMutableTransaction tx;
31-
tx.vin.push_back(CTxIn{MineBlock(test_setup->m_node, P2WSH_OP_TRUE)});
31+
tx.vin.emplace_back(MineBlock(test_setup->m_node, P2WSH_OP_TRUE));
3232
tx.vin.back().scriptWitness = witness;
3333
tx.vout.emplace_back(1337, P2WSH_OP_TRUE);
3434
if (NUM_BLOCKS - b >= COINBASE_MATURITY)

src/bench/disconnected_transactions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ static BlockTxns CreateRandomTransactions(size_t num_txns)
3636
CScript spk = CScript() << OP_TRUE;
3737
for (uint32_t i = 0; i < num_txns; ++i) {
3838
CMutableTransaction tx;
39-
tx.vin.emplace_back(CTxIn{COutPoint{prevout_hash, 0}});
40-
tx.vout.emplace_back(CTxOut{CENT, spk});
39+
tx.vin.emplace_back(COutPoint{prevout_hash, 0});
40+
tx.vout.emplace_back(CENT, spk);
4141
auto ptx{MakeTransactionRef(tx)};
4242
txns.emplace_back(ptx);
4343
prevout_hash = ptx->GetHash();

src/bench/wallet_loading.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ namespace wallet{
2020
static void AddTx(CWallet& wallet)
2121
{
2222
CMutableTransaction mtx;
23-
mtx.vout.push_back({COIN, GetScriptForDestination(*Assert(wallet.GetNewDestination(OutputType::BECH32, "")))});
24-
mtx.vin.push_back(CTxIn());
23+
mtx.vout.emplace_back(COIN, GetScriptForDestination(*Assert(wallet.GetNewDestination(OutputType::BECH32, ""))));
24+
mtx.vin.emplace_back();
2525

2626
wallet.AddToWallet(MakeTransactionRef(mtx), TxStateInactive{});
2727
}

src/common/args.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
216216
m_command.push_back(key);
217217
while (++i < argc) {
218218
// The remaining args are command args
219-
m_command.push_back(argv[i]);
219+
m_command.emplace_back(argv[i]);
220220
}
221221
break;
222222
}

src/external_signer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ bool ExternalSigner::Enumerate(const std::string& command, std::vector<ExternalS
5454
if (model_field.isStr() && model_field.getValStr() != "") {
5555
name += model_field.getValStr();
5656
}
57-
signers.push_back(ExternalSigner(command, chain, fingerprintStr, name));
57+
signers.emplace_back(command, chain, fingerprintStr, name);
5858
}
5959
return true;
6060
}

src/headerssync.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ bool HeadersSyncState::ValidateAndStoreRedownloadedHeader(const CBlockHeader& he
271271
}
272272

273273
// Store this header for later processing.
274-
m_redownloaded_headers.push_back(header);
274+
m_redownloaded_headers.emplace_back(header);
275275
m_redownload_buffer_last_height = next_height;
276276
m_redownload_buffer_last_hash = header.GetHash();
277277

src/httpserver.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ static bool ClientAllowed(const CNetAddr& netaddr)
221221
static bool InitHTTPAllowList()
222222
{
223223
rpc_allow_subnets.clear();
224-
rpc_allow_subnets.push_back(CSubNet{LookupHost("127.0.0.1", false).value(), 8}); // always allow IPv4 local subnet
225-
rpc_allow_subnets.push_back(CSubNet{LookupHost("::1", false).value()}); // always allow IPv6 localhost
224+
rpc_allow_subnets.emplace_back(LookupHost("127.0.0.1", false).value(), 8); // always allow IPv4 local subnet
225+
rpc_allow_subnets.emplace_back(LookupHost("::1", false).value()); // always allow IPv6 localhost
226226
for (const std::string& strAllow : gArgs.GetArgs("-rpcallowip")) {
227227
CSubNet subnet;
228228
LookupSubNet(strAllow, subnet);
@@ -364,8 +364,8 @@ static bool HTTPBindAddresses(struct evhttp* http)
364364

365365
// Determine what addresses to bind to
366366
if (!(gArgs.IsArgSet("-rpcallowip") && gArgs.IsArgSet("-rpcbind"))) { // Default to loopback if not allowing external IPs
367-
endpoints.push_back(std::make_pair("::1", http_port));
368-
endpoints.push_back(std::make_pair("127.0.0.1", http_port));
367+
endpoints.emplace_back("::1", http_port);
368+
endpoints.emplace_back("127.0.0.1", http_port);
369369
if (gArgs.IsArgSet("-rpcallowip")) {
370370
LogPrintf("WARNING: option -rpcallowip was specified without -rpcbind; this doesn't usually make sense\n");
371371
}
@@ -377,7 +377,7 @@ static bool HTTPBindAddresses(struct evhttp* http)
377377
uint16_t port{http_port};
378378
std::string host;
379379
SplitHostPort(strRPCBind, port, host);
380-
endpoints.push_back(std::make_pair(host, port));
380+
endpoints.emplace_back(host, port);
381381
}
382382
}
383383

@@ -746,7 +746,7 @@ void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPR
746746
{
747747
LogPrint(BCLog::HTTP, "Registering HTTP handler for %s (exactmatch %d)\n", prefix, exactMatch);
748748
LOCK(g_httppathhandlers_mutex);
749-
pathHandlers.push_back(HTTPPathHandler(prefix, exactMatch, handler));
749+
pathHandlers.emplace_back(prefix, exactMatch, handler);
750750
}
751751

752752
void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)

0 commit comments

Comments
 (0)