Skip to content

Commit b4f1dfc

Browse files
fanquakevijaydasmp
authored andcommitted
Merge 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 Merge 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 Merge 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 Merge 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
1 parent 36f1e1e commit b4f1dfc

31 files changed

+106
-103
lines changed

src/.bear-tidy-config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"src/leveldb",
1313
"src/minisketch",
1414
"src/univalue",
15+
"src/bench/nanobench.cpp",
16+
"src/bench/nanobench.h",
1517
"src/secp256k1"
1618
]
1719
},

src/.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ bugprone-argument-comment,
44
bugprone-use-after-move,
55
misc-unused-using-decls,
66
modernize-use-default-member-init,
7+
modernize-use-emplace,
78
modernize-use-nullptr,
89
performance-for-range-copy,
910
performance-move-const-arg,

src/bench/block_assemble.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static void AssembleBlock(benchmark::Bench& bench)
3232
std::array<CTransactionRef, NUM_BLOCKS - COINBASE_MATURITY + 1> txs;
3333
for (size_t b{0}; b < NUM_BLOCKS; ++b) {
3434
CMutableTransaction tx;
35-
tx.vin.push_back(MineBlock(test_setup->m_node, SCRIPT_PUB));
35+
tx.vin.emplace_back(MineBlock(test_setup->m_node, SCRIPT_PUB));
3636
tx.vin.back().scriptSig = scriptSig;
3737
tx.vout.emplace_back(1337, SCRIPT_PUB);
3838
if (NUM_BLOCKS - b >= COINBASE_MATURITY)

src/bench/wallet_loading.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ static void BenchUnloadWallet(std::shared_ptr<CWallet>&& wallet)
4646
static void AddTx(CWallet& wallet)
4747
{
4848
CMutableTransaction mtx;
49-
mtx.vout.push_back({COIN, GetScriptForDestination(*Assert(wallet.GetNewDestination("")))});
50-
mtx.vin.push_back(CTxIn());
49+
mtx.vout.emplace_back(COIN, GetScriptForDestination(*Assert(wallet.GetNewDestination(""))));
50+
mtx.vin.emplace_back(CTxIn());
5151

5252
wallet.AddToWallet(MakeTransactionRef(mtx), TxStateInactive{});
5353
}

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/httpserver.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ static bool ClientAllowed(const CNetAddr& netaddr)
177177
static bool InitHTTPAllowList()
178178
{
179179
rpc_allow_subnets.clear();
180-
rpc_allow_subnets.push_back(CSubNet{LookupHost("127.0.0.1", false).value(), 8}); // always allow IPv4 local subnet
181-
rpc_allow_subnets.push_back(CSubNet{LookupHost("::1", false).value()}); // always allow IPv6 localhost
180+
rpc_allow_subnets.emplace_back(LookupHost("127.0.0.1", false).value(), 8); // always allow IPv4 local subnet
181+
rpc_allow_subnets.emplace_back(LookupHost("::1", false).value()); // always allow IPv6 localhost
182182
for (const std::string& strAllow : gArgs.GetArgs("-rpcallowip")) {
183183
const CSubNet subnet{LookupSubNet(strAllow)};
184184
if (!subnet.IsValid()) {
@@ -330,8 +330,8 @@ static bool HTTPBindAddresses(struct evhttp* http)
330330

331331
// Determine what addresses to bind to
332332
if (!(gArgs.IsArgSet("-rpcallowip") && gArgs.IsArgSet("-rpcbind"))) { // Default to loopback if not allowing external IPs
333-
endpoints.push_back(std::make_pair("::1", http_port));
334-
endpoints.push_back(std::make_pair("127.0.0.1", http_port));
333+
endpoints.emplace_back("::1", http_port);
334+
endpoints.emplace_back("127.0.0.1", http_port);
335335
if (gArgs.IsArgSet("-rpcallowip")) {
336336
LogPrintf("WARNING: option -rpcallowip was specified without -rpcbind; this doesn't usually make sense\n");
337337
}
@@ -343,7 +343,7 @@ static bool HTTPBindAddresses(struct evhttp* http)
343343
uint16_t port{http_port};
344344
std::string host;
345345
SplitHostPort(strRPCBind, port, host);
346-
endpoints.push_back(std::make_pair(host, port));
346+
endpoints.emplace_back(host, port);
347347
}
348348
} else { // No specific bind address specified, bind to any
349349
endpoints.push_back(std::make_pair("::", http_port));
@@ -706,7 +706,7 @@ void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPR
706706
{
707707
LogPrint(BCLog::HTTP, "Registering HTTP handler for %s (exactmatch %d)\n", prefix, exactMatch);
708708
LOCK(g_httppathhandlers_mutex);
709-
pathHandlers.push_back(HTTPPathHandler(prefix, exactMatch, handler));
709+
pathHandlers.emplace_back(prefix, exactMatch, handler);
710710
}
711711

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

src/net_permissions.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ bool TryParsePermissionFlags(const std::string& str, NetPermissionFlags& output,
7171
std::vector<std::string> NetPermissions::ToStrings(NetPermissionFlags flags)
7272
{
7373
std::vector<std::string> strings;
74-
if (NetPermissions::HasFlag(flags, NetPermissionFlags::BloomFilter)) strings.push_back("bloomfilter");
75-
if (NetPermissions::HasFlag(flags, NetPermissionFlags::NoBan)) strings.push_back("noban");
76-
if (NetPermissions::HasFlag(flags, NetPermissionFlags::ForceRelay)) strings.push_back("forcerelay");
77-
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Relay)) strings.push_back("relay");
78-
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Mempool)) strings.push_back("mempool");
79-
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Download)) strings.push_back("download");
80-
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Addr)) strings.push_back("addr");
74+
if (NetPermissions::HasFlag(flags, NetPermissionFlags::BloomFilter)) strings.emplace_back("bloomfilter");
75+
if (NetPermissions::HasFlag(flags, NetPermissionFlags::NoBan)) strings.emplace_back("noban");
76+
if (NetPermissions::HasFlag(flags, NetPermissionFlags::ForceRelay)) strings.emplace_back("forcerelay");
77+
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Relay)) strings.emplace_back("relay");
78+
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Mempool)) strings.emplace_back("mempool");
79+
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Download)) strings.emplace_back("download");
80+
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Addr)) strings.emplace_back("addr");
8181
return strings;
8282
}
8383

src/net_processing.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2799,7 +2799,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
27992799
// and we want it right after the last block so they don't
28002800
// wait for other stuff first.
28012801
std::vector<CInv> vInv;
2802-
vInv.push_back(CInv(MSG_BLOCK, m_chainman.ActiveChain().Tip()->GetBlockHash()));
2802+
vInv.emplace_back(MSG_BLOCK, m_chainman.ActiveChain().Tip()->GetBlockHash());
28032803
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::INV, vInv));
28042804
peer.m_continuation_block.SetNull();
28052805
}
@@ -3199,7 +3199,7 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c
31993199
// Can't download any more from this peer
32003200
break;
32013201
}
3202-
vGetData.push_back(CInv(MSG_BLOCK, pindex->GetBlockHash()));
3202+
vGetData.emplace_back(CInv(MSG_BLOCK, pindex->GetBlockHash()));
32033203
BlockRequested(pfrom.GetId(), *pindex);
32043204
LogPrint(BCLog::NET, "Requesting block %s from peer=%d\n",
32053205
pindex->GetBlockHash().ToString(), pfrom.GetId());
@@ -4616,7 +4616,7 @@ void PeerManagerImpl::ProcessMessage(
46164616
const auto send_headers = [this /* for m_connman */, &hashStop, &pindex, &nodestate, &pfrom, &msgMaker](auto msg_type_internal, auto& v_headers, auto callback) {
46174617
int nLimit = GetHeadersLimit(pfrom, msg_type_internal == NetMsgType::HEADERS2);
46184618
for (; pindex; pindex = m_chainman.ActiveChain().Next(pindex)) {
4619-
v_headers.push_back(callback(pindex));
4619+
v_headers.emplace_back(callback(pindex));
46204620

46214621
if (--nLimit <= 0 || pindex->GetBlockHash() == hashStop)
46224622
break;
@@ -6167,14 +6167,14 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
61676167
}
61686168
if (fFoundStartingHeader) {
61696169
// add this to the headers message
6170-
vHeaders.push_back(pindex->GetBlockHeader());
6170+
vHeaders.emplace_back(pindex->GetBlockHeader());
61716171
} else if (PeerHasHeader(&state, pindex)) {
61726172
continue; // keep looking for the first new block
61736173
} else if (pindex->pprev == nullptr || PeerHasHeader(&state, pindex->pprev) || isPrevDevnetGenesisBlock) {
61746174
// Peer doesn't have this header but they do have the prior one.
61756175
// Start sending headers.
61766176
fFoundStartingHeader = true;
6177-
vHeaders.push_back(pindex->GetBlockHeader());
6177+
vHeaders.emplace_back(pindex->GetBlockHeader());
61786178
} else {
61796179
// Peer doesn't have this header or the prior one -- nothing will
61806180
// connect, so bail out.
@@ -6282,7 +6282,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
62826282

62836283
// Add blocks
62846284
for (const uint256& hash : peer->m_blocks_for_inv_relay) {
6285-
vInv.push_back(CInv(MSG_BLOCK, hash));
6285+
vInv.emplace_back(MSG_BLOCK, hash);
62866286
if (vInv.size() == MAX_INV_SZ) {
62876287
m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
62886288
vInv.clear();
@@ -6527,7 +6527,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
65276527
NodeId staller = -1;
65286528
FindNextBlocksToDownload(*peer, MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller);
65296529
for (const CBlockIndex *pindex : vToDownload) {
6530-
vGetData.push_back(CInv(MSG_BLOCK, pindex->GetBlockHash()));
6530+
vGetData.emplace_back(CInv(MSG_BLOCK, pindex->GetBlockHash()));
65316531
BlockRequested(pto->GetId(), *pindex);
65326532
LogPrint(BCLog::NET, "Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(),
65336533
pindex->nHeight, pto->GetId());

src/node/blockstorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ bool BlockManager::WriteBlockIndexDB()
331331
std::vector<std::pair<int, const CBlockFileInfo*>> vFiles;
332332
vFiles.reserve(m_dirty_fileinfo.size());
333333
for (std::set<int>::iterator it = m_dirty_fileinfo.begin(); it != m_dirty_fileinfo.end();) {
334-
vFiles.push_back(std::make_pair(*it, &m_blockfile_info[*it]));
334+
vFiles.emplace_back(*it, &m_blockfile_info[*it]);
335335
m_dirty_fileinfo.erase(it++);
336336
}
337337
std::vector<const CBlockIndex*> vBlocks;

src/qt/rpcconsole.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class PeerIdViewDelegate : public QStyledItemDelegate
184184
bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut, const WalletModel* wallet_model)
185185
{
186186
std::vector< std::vector<std::string> > stack;
187-
stack.push_back(std::vector<std::string>());
187+
stack.emplace_back();
188188

189189
enum CmdParseState
190190
{
@@ -212,7 +212,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
212212
}
213213
// Make sure stack is not empty before adding something
214214
if (stack.empty()) {
215-
stack.push_back(std::vector<std::string>());
215+
stack.emplace_back();
216216
}
217217
stack.back().push_back(strArg);
218218
};
@@ -221,7 +221,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
221221
if (nDepthInsideSensitive) {
222222
if (!--nDepthInsideSensitive) {
223223
assert(filter_begin_pos);
224-
filter_ranges.push_back(std::make_pair(filter_begin_pos, chpos));
224+
filter_ranges.emplace_back(filter_begin_pos, chpos);
225225
filter_begin_pos = 0;
226226
}
227227
}
@@ -321,7 +321,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
321321
if (nDepthInsideSensitive) {
322322
++nDepthInsideSensitive;
323323
}
324-
stack.push_back(std::vector<std::string>());
324+
stack.emplace_back();
325325
}
326326

327327
// don't allow commands after executed commands on baselevel

0 commit comments

Comments
 (0)