diff --git a/src/.bear-tidy-config b/src/.bear-tidy-config index 9b6b9d2cf7..0ab30a8d9d 100644 --- a/src/.bear-tidy-config +++ b/src/.bear-tidy-config @@ -8,6 +8,8 @@ "src/crypto/ctaes", "src/leveldb", "src/minisketch", + "src/bench/nanobench.cpp", + "src/bench/nanobench.h", "src/secp256k1" ] }, diff --git a/src/.clang-tidy b/src/.clang-tidy index 9f16553706..0318bd01ce 100644 --- a/src/.clang-tidy +++ b/src/.clang-tidy @@ -5,6 +5,7 @@ bugprone-argument-comment, bugprone-use-after-move, misc-unused-using-decls, modernize-use-default-member-init, +modernize-use-emplace, modernize-use-noexcept, modernize-use-nullptr, performance-*, diff --git a/src/addrman.cpp b/src/addrman.cpp index 6ce9c81c63..b001365ab3 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -854,7 +854,7 @@ std::vector> AddrManImpl::GetEntries_(bool /*multiplicity_in=*/from_tried ? 1 : info.nRefCount, bucket, position); - infos.push_back(std::make_pair(info, location)); + infos.emplace_back(info, location); } } } diff --git a/src/bench/block_assemble.cpp b/src/bench/block_assemble.cpp index 0737144b84..ba8ec16119 100644 --- a/src/bench/block_assemble.cpp +++ b/src/bench/block_assemble.cpp @@ -28,7 +28,7 @@ static void AssembleBlock(benchmark::Bench& bench) std::array txs; for (size_t b{0}; b < NUM_BLOCKS; ++b) { CMutableTransaction tx; - tx.vin.push_back(CTxIn{MineBlock(test_setup->m_node, P2WSH_OP_TRUE)}); + tx.vin.emplace_back(MineBlock(test_setup->m_node, P2WSH_OP_TRUE)); tx.vin.back().scriptWitness = witness; tx.vout.emplace_back(1337, P2WSH_OP_TRUE); if (NUM_BLOCKS - b >= COINBASE_MATURITY) diff --git a/src/bench/disconnected_transactions.cpp b/src/bench/disconnected_transactions.cpp index 0a7344b248..264c0aa1e8 100644 --- a/src/bench/disconnected_transactions.cpp +++ b/src/bench/disconnected_transactions.cpp @@ -36,8 +36,8 @@ static BlockTxns CreateRandomTransactions(size_t num_txns) CScript spk = CScript() << OP_TRUE; for (uint32_t i = 0; i < num_txns; ++i) { CMutableTransaction tx; - tx.vin.emplace_back(CTxIn{COutPoint{prevout_hash, 0}}); - tx.vout.emplace_back(CTxOut{CENT, spk}); + tx.vin.emplace_back(COutPoint{prevout_hash, 0}); + tx.vout.emplace_back(CENT, spk); auto ptx{MakeTransactionRef(tx)}; txns.emplace_back(ptx); prevout_hash = ptx->GetHash(); diff --git a/src/bench/wallet_loading.cpp b/src/bench/wallet_loading.cpp index 5453238728..b17c7fe05a 100644 --- a/src/bench/wallet_loading.cpp +++ b/src/bench/wallet_loading.cpp @@ -20,8 +20,8 @@ namespace wallet{ static void AddTx(CWallet& wallet) { CMutableTransaction mtx; - mtx.vout.push_back({COIN, GetScriptForDestination(*Assert(wallet.GetNewDestination(OutputType::BECH32, "")))}); - mtx.vin.push_back(CTxIn()); + mtx.vout.emplace_back(COIN, GetScriptForDestination(*Assert(wallet.GetNewDestination(OutputType::BECH32, "")))); + mtx.vin.emplace_back(); wallet.AddToWallet(MakeTransactionRef(mtx), TxStateInactive{}); } diff --git a/src/common/args.cpp b/src/common/args.cpp index 643838399f..ca04175696 100644 --- a/src/common/args.cpp +++ b/src/common/args.cpp @@ -216,7 +216,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin m_command.push_back(key); while (++i < argc) { // The remaining args are command args - m_command.push_back(argv[i]); + m_command.emplace_back(argv[i]); } break; } diff --git a/src/external_signer.cpp b/src/external_signer.cpp index 6b1e1f0241..102c58b56a 100644 --- a/src/external_signer.cpp +++ b/src/external_signer.cpp @@ -54,7 +54,7 @@ bool ExternalSigner::Enumerate(const std::string& command, std::vector NetPermissions::ToStrings(NetPermissionFlags flags) { std::vector strings; - if (NetPermissions::HasFlag(flags, NetPermissionFlags::BloomFilter)) strings.push_back("bloomfilter"); - if (NetPermissions::HasFlag(flags, NetPermissionFlags::NoBan)) strings.push_back("noban"); - if (NetPermissions::HasFlag(flags, NetPermissionFlags::ForceRelay)) strings.push_back("forcerelay"); - if (NetPermissions::HasFlag(flags, NetPermissionFlags::Relay)) strings.push_back("relay"); - if (NetPermissions::HasFlag(flags, NetPermissionFlags::Mempool)) strings.push_back("mempool"); - if (NetPermissions::HasFlag(flags, NetPermissionFlags::Download)) strings.push_back("download"); - if (NetPermissions::HasFlag(flags, NetPermissionFlags::Addr)) strings.push_back("addr"); + if (NetPermissions::HasFlag(flags, NetPermissionFlags::BloomFilter)) strings.emplace_back("bloomfilter"); + if (NetPermissions::HasFlag(flags, NetPermissionFlags::NoBan)) strings.emplace_back("noban"); + if (NetPermissions::HasFlag(flags, NetPermissionFlags::ForceRelay)) strings.emplace_back("forcerelay"); + if (NetPermissions::HasFlag(flags, NetPermissionFlags::Relay)) strings.emplace_back("relay"); + if (NetPermissions::HasFlag(flags, NetPermissionFlags::Mempool)) strings.emplace_back("mempool"); + if (NetPermissions::HasFlag(flags, NetPermissionFlags::Download)) strings.emplace_back("download"); + if (NetPermissions::HasFlag(flags, NetPermissionFlags::Addr)) strings.emplace_back("addr"); return strings; } diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 84ccc54f03..f07769272c 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2359,7 +2359,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv& // and we want it right after the last block so they don't // wait for other stuff first. std::vector vInv; - vInv.push_back(CInv(MSG_BLOCK, m_chainman.ActiveChain().Tip()->GetBlockHash())); + vInv.emplace_back(MSG_BLOCK, m_chainman.ActiveChain().Tip()->GetBlockHash()); m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::INV, vInv)); peer.m_continuation_block.SetNull(); } @@ -2761,7 +2761,7 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c break; } uint32_t nFetchFlags = GetFetchFlags(peer); - vGetData.push_back(CInv(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash())); + vGetData.emplace_back(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash()); BlockRequested(pfrom.GetId(), *pindex); LogPrint(BCLog::NET, "Requesting block %s from peer=%d\n", pindex->GetBlockHash().ToString(), pfrom.GetId()); @@ -3299,7 +3299,7 @@ void PeerManagerImpl::ProcessCompactBlockTxns(CNode& pfrom, Peer& peer, const Bl if (first_in_flight) { // Might have collided, fall back to getdata now :( std::vector invs; - invs.push_back(CInv(MSG_BLOCK | GetFetchFlags(peer), block_transactions.blockhash)); + invs.emplace_back(MSG_BLOCK | GetFetchFlags(peer), block_transactions.blockhash); m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETDATA, invs)); } else { RemoveBlockRequest(block_transactions.blockhash, pfrom.GetId()); @@ -4149,7 +4149,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, LogPrint(BCLog::NET, "getheaders %d to %s from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.IsNull() ? "end" : hashStop.ToString(), pfrom.GetId()); for (; pindex; pindex = m_chainman.ActiveChain().Next(pindex)) { - vHeaders.push_back(pindex->GetBlockHeader()); + vHeaders.emplace_back(pindex->GetBlockHeader()); if (--nLimit <= 0 || pindex->GetBlockHash() == hashStop) break; } @@ -5649,14 +5649,14 @@ bool PeerManagerImpl::SendMessages(CNode* pto) pBestIndex = pindex; if (fFoundStartingHeader) { // add this to the headers message - vHeaders.push_back(pindex->GetBlockHeader()); + vHeaders.emplace_back(pindex->GetBlockHeader()); } else if (PeerHasHeader(&state, pindex)) { continue; // keep looking for the first new block } else if (pindex->pprev == nullptr || PeerHasHeader(&state, pindex->pprev)) { // Peer doesn't have this header but they do have the prior one. // Start sending headers. fFoundStartingHeader = true; - vHeaders.push_back(pindex->GetBlockHeader()); + vHeaders.emplace_back(pindex->GetBlockHeader()); } else { // Peer doesn't have this header or the prior one -- nothing will // connect, so bail out. @@ -5742,7 +5742,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto) // Add blocks for (const uint256& hash : peer->m_blocks_for_inv_relay) { - vInv.push_back(CInv(MSG_BLOCK, hash)); + vInv.emplace_back(MSG_BLOCK, hash); if (vInv.size() == MAX_INV_SZ) { m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv)); vInv.clear(); @@ -5948,7 +5948,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto) } for (const CBlockIndex *pindex : vToDownload) { uint32_t nFetchFlags = GetFetchFlags(*peer); - vGetData.push_back(CInv(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash())); + vGetData.emplace_back(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash()); BlockRequested(pto->GetId(), *pindex); LogPrint(BCLog::NET, "Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(), pindex->nHeight, pto->GetId()); diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index 931db80274..f8f1aab551 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -458,7 +458,7 @@ bool BlockManager::WriteBlockIndexDB() std::vector> vFiles; vFiles.reserve(m_dirty_fileinfo.size()); for (std::set::iterator it = m_dirty_fileinfo.begin(); it != m_dirty_fileinfo.end();) { - vFiles.push_back(std::make_pair(*it, &m_blockfile_info[*it])); + vFiles.emplace_back(*it, &m_blockfile_info[*it]); m_dirty_fileinfo.erase(it++); } std::vector vBlocks; diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 4baa0da67c..f6dbe4f008 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -674,7 +674,7 @@ public: if (!m_node.mempool) { std::map bump_fees; for (const auto& outpoint : outpoints) { - bump_fees.emplace(std::make_pair(outpoint, 0)); + bump_fees.emplace(outpoint, 0); } return bump_fees; } diff --git a/src/psbt.h b/src/psbt.h index 48e0453084..5b4daafed5 100644 --- a/src/psbt.h +++ b/src/psbt.h @@ -874,7 +874,7 @@ struct PSBTOutput if ((leaf_ver & ~TAPROOT_LEAF_MASK) != 0) { throw std::ios_base::failure("Output Taproot tree has a leaf with an invalid leaf version"); } - m_tap_tree.push_back(std::make_tuple(depth, leaf_ver, script)); + m_tap_tree.emplace_back(depth, leaf_ver, script); builder.Add((int)depth, script, (int)leaf_ver, /*track=*/true); } if (!builder.IsComplete()) { diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 998a4e5cbe..ceaa3ac46b 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -169,7 +169,7 @@ public: bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut, const WalletModel* wallet_model) { std::vector< std::vector > stack; - stack.push_back(std::vector()); + stack.emplace_back(); enum CmdParseState { @@ -197,7 +197,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes } // Make sure stack is not empty before adding something if (stack.empty()) { - stack.push_back(std::vector()); + stack.emplace_back(); } stack.back().push_back(strArg); }; @@ -206,7 +206,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes if (nDepthInsideSensitive) { if (!--nDepthInsideSensitive) { assert(filter_begin_pos); - filter_ranges.push_back(std::make_pair(filter_begin_pos, chpos)); + filter_ranges.emplace_back(filter_begin_pos, chpos); filter_begin_pos = 0; } } @@ -306,7 +306,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes if (nDepthInsideSensitive) { ++nDepthInsideSensitive; } - stack.push_back(std::vector()); + stack.emplace_back(); } // don't allow commands after executed commands on baselevel diff --git a/src/rest.cpp b/src/rest.cpp index ba149c1a9e..e094039366 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -798,7 +798,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std:: return RESTERR(req, HTTP_BAD_REQUEST, "Parse error"); txid.SetHex(strTxid); - vOutPoints.push_back(COutPoint(txid, (uint32_t)nOutput)); + vOutPoints.emplace_back(txid, (uint32_t)nOutput); } if (vOutPoints.size() > 0) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 31dd8164fe..ab710d868a 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1930,7 +1930,7 @@ static RPCHelpMan getblockstats() // New feerate uses satoshis per virtual byte instead of per serialized byte CAmount feerate = weight ? (txfee * WITNESS_SCALE_FACTOR) / weight : 0; if (do_feerate_percentiles) { - feerate_array.emplace_back(std::make_pair(feerate, weight)); + feerate_array.emplace_back(feerate, weight); } maxfeerate = std::max(maxfeerate, feerate); minfeerate = std::min(minfeerate, feerate); diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 31ca126862..16705b3ce2 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -1581,10 +1581,10 @@ static RPCHelpMan createpsbt() PartiallySignedTransaction psbtx; psbtx.tx = rawTx; for (unsigned int i = 0; i < rawTx.vin.size(); ++i) { - psbtx.inputs.push_back(PSBTInput()); + psbtx.inputs.emplace_back(); } for (unsigned int i = 0; i < rawTx.vout.size(); ++i) { - psbtx.outputs.push_back(PSBTOutput()); + psbtx.outputs.emplace_back(); } // Serialize the PSBT @@ -1648,10 +1648,10 @@ static RPCHelpMan converttopsbt() PartiallySignedTransaction psbtx; psbtx.tx = tx; for (unsigned int i = 0; i < tx.vin.size(); ++i) { - psbtx.inputs.push_back(PSBTInput()); + psbtx.inputs.emplace_back(); } for (unsigned int i = 0; i < tx.vout.size(); ++i) { - psbtx.outputs.push_back(PSBTOutput()); + psbtx.outputs.emplace_back(); } // Serialize the PSBT diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index daf751111f..d3c5a19326 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -88,7 +88,7 @@ std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest& vCommands.reserve(mapCommands.size()); for (const auto& entry : mapCommands) - vCommands.push_back(make_pair(entry.second.front()->category + entry.first, entry.second.front())); + vCommands.emplace_back(entry.second.front()->category + entry.first, entry.second.front()); sort(vCommands.begin(), vCommands.end()); JSONRPCRequest jreq = helpreq; diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 248ad780c3..251a8420f7 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -433,7 +433,7 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator case TxoutType::SCRIPTHASH: { uint160 h160{vSolutions[0]}; if (GetCScript(provider, sigdata, CScriptID{h160}, scriptRet)) { - ret.push_back(std::vector(scriptRet.begin(), scriptRet.end())); + ret.emplace_back(scriptRet.begin(), scriptRet.end()); return true; } // Could not find redeemScript, add to missing @@ -442,7 +442,7 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator } case TxoutType::MULTISIG: { size_t required = vSolutions.front()[0]; - ret.push_back(valtype()); // workaround CHECKMULTISIG bug + ret.emplace_back(); // workaround CHECKMULTISIG bug for (size_t i = 1; i < vSolutions.size() - 1; ++i) { CPubKey pubkey = CPubKey(vSolutions[i]); // We need to always call CreateSig in order to fill sigdata with all @@ -456,7 +456,7 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator } bool ok = ret.size() == required + 1; for (size_t i = 0; i + ret.size() < required + 1; ++i) { - ret.push_back(valtype()); + ret.emplace_back(); } return ok; } @@ -466,7 +466,7 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator case TxoutType::WITNESS_V0_SCRIPTHASH: if (GetCScript(provider, sigdata, CScriptID{RIPEMD160(vSolutions[0])}, scriptRet)) { - ret.push_back(std::vector(scriptRet.begin(), scriptRet.end())); + ret.emplace_back(scriptRet.begin(), scriptRet.end()); return true; } // Could not find witnessScript, add to missing @@ -544,7 +544,7 @@ bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreato const auto ms = miniscript::FromScript(witnessscript, ms_satisfier); solved = ms && ms->Satisfy(ms_satisfier, result) == miniscript::Availability::YES; } - result.push_back(std::vector(witnessscript.begin(), witnessscript.end())); + result.emplace_back(witnessscript.begin(), witnessscript.end()); sigdata.scriptWitness.stack = result; sigdata.witness = true; @@ -561,7 +561,7 @@ bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreato if (!sigdata.witness) sigdata.scriptWitness.stack.clear(); if (P2SH) { - result.push_back(std::vector(subscript.begin(), subscript.end())); + result.emplace_back(subscript.begin(), subscript.end()); } sigdata.scriptSig = PushAll(result); diff --git a/src/script/signingprovider.cpp b/src/script/signingprovider.cpp index 168b3030cc..ff02ab5a12 100644 --- a/src/script/signingprovider.cpp +++ b/src/script/signingprovider.cpp @@ -368,6 +368,8 @@ TaprootBuilder& TaprootBuilder::Add(int depth, Span script, /* Construct NodeInfo object with leaf hash and (if track is true) also leaf information. */ NodeInfo node; node.hash = ComputeTapleafHash(leaf_version, script); + // due to bug in clang-tidy-17: + // NOLINTNEXTLINE(modernize-use-emplace) if (track) node.leaves.emplace_back(LeafInfo{std::vector(script.begin(), script.end()), leaf_version, {}}); /* Insert into the branch. */ Insert(std::move(node), depth); @@ -569,7 +571,7 @@ std::vector>> TaprootBui assert(leaf.merkle_branch.size() <= TAPROOT_CONTROL_MAX_NODE_COUNT); uint8_t depth = (uint8_t)leaf.merkle_branch.size(); uint8_t leaf_ver = (uint8_t)leaf.leaf_version; - tuples.push_back(std::make_tuple(depth, leaf_ver, leaf.script)); + tuples.emplace_back(depth, leaf_ver, leaf.script); } } return tuples; diff --git a/src/test/addrman_tests.cpp b/src/test/addrman_tests.cpp index b01ba81c5f..bfefc3ff97 100644 --- a/src/test/addrman_tests.cpp +++ b/src/test/addrman_tests.cpp @@ -98,8 +98,8 @@ BOOST_AUTO_TEST_CASE(addrman_simple) // Test: reset addrman and test AddrMan::Add multiple addresses works as expected addrman = std::make_unique(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)); std::vector vAddr; - vAddr.push_back(CAddress(ResolveService("250.1.1.3", 8333), NODE_NONE)); - vAddr.push_back(CAddress(ResolveService("250.1.1.4", 8333), NODE_NONE)); + vAddr.emplace_back(ResolveService("250.1.1.3", 8333), NODE_NONE); + vAddr.emplace_back(ResolveService("250.1.1.4", 8333), NODE_NONE); BOOST_CHECK(addrman->Add(vAddr, source)); BOOST_CHECK(addrman->Size() >= 1); } diff --git a/src/test/bip32_tests.cpp b/src/test/bip32_tests.cpp index fe3d8995e9..cbbec94e00 100644 --- a/src/test/bip32_tests.cpp +++ b/src/test/bip32_tests.cpp @@ -29,7 +29,7 @@ struct TestVector { explicit TestVector(std::string strHexMasterIn) : strHexMaster(strHexMasterIn) {} TestVector& operator()(std::string pub, std::string prv, unsigned int nChild) { - vDerive.push_back(TestDerivation()); + vDerive.emplace_back(); TestDerivation &der = vDerive.back(); der.pub = pub; der.prv = prv; diff --git a/src/test/fuzz/mini_miner.cpp b/src/test/fuzz/mini_miner.cpp index e17e2bad60..2f53943c31 100644 --- a/src/test/fuzz/mini_miner.cpp +++ b/src/test/fuzz/mini_miner.cpp @@ -25,7 +25,7 @@ void initialize_miner() static const auto testing_setup = MakeNoLogFileContext(); g_setup = testing_setup.get(); for (uint32_t i = 0; i < uint32_t{100}; ++i) { - g_available_coins.push_back(COutPoint{uint256::ZERO, i}); + g_available_coins.emplace_back(uint256::ZERO, i); } } @@ -45,11 +45,11 @@ FUZZ_TARGET(mini_miner, .init = initialize_miner) const size_t num_outputs = fuzzed_data_provider.ConsumeIntegralInRange(1, 50); for (size_t n{0}; n < num_inputs; ++n) { auto prevout = available_coins.front(); - mtx.vin.push_back(CTxIn(prevout, CScript())); + mtx.vin.emplace_back(prevout, CScript()); available_coins.pop_front(); } for (uint32_t n{0}; n < num_outputs; ++n) { - mtx.vout.push_back(CTxOut(100, P2WSH_OP_TRUE)); + mtx.vout.emplace_back(100, P2WSH_OP_TRUE); } CTransactionRef tx = MakeTransactionRef(mtx); TestMemPoolEntryHelper entry; @@ -60,14 +60,14 @@ FUZZ_TARGET(mini_miner, .init = initialize_miner) // All outputs are available to spend for (uint32_t n{0}; n < num_outputs; ++n) { if (fuzzed_data_provider.ConsumeBool()) { - available_coins.push_back(COutPoint{tx->GetHash(), n}); + available_coins.emplace_back(tx->GetHash(), n); } } if (fuzzed_data_provider.ConsumeBool() && !tx->vout.empty()) { // Add outpoint from this tx (may or not be spent by a later tx) - outpoints.push_back(COutPoint{tx->GetHash(), - (uint32_t)fuzzed_data_provider.ConsumeIntegralInRange(0, tx->vout.size())}); + outpoints.emplace_back(tx->GetHash(), + (uint32_t)fuzzed_data_provider.ConsumeIntegralInRange(0, tx->vout.size())); } else { // Add some random outpoint (will be interpreted as confirmed or not yet submitted // to mempool). @@ -123,11 +123,11 @@ FUZZ_TARGET(mini_miner_selection, .init = initialize_miner) const size_t num_outputs = fuzzed_data_provider.ConsumeIntegralInRange(2, 5); for (size_t n{0}; n < num_inputs; ++n) { auto prevout = available_coins.at(0); - mtx.vin.push_back(CTxIn(prevout, CScript())); + mtx.vin.emplace_back(prevout, CScript()); available_coins.pop_front(); } for (uint32_t n{0}; n < num_outputs; ++n) { - mtx.vout.push_back(CTxOut(100, P2WSH_OP_TRUE)); + mtx.vout.emplace_back(100, P2WSH_OP_TRUE); } CTransactionRef tx = MakeTransactionRef(mtx); @@ -136,9 +136,9 @@ FUZZ_TARGET(mini_miner_selection, .init = initialize_miner) // MiniMiner interprets spent coins as to-be-replaced and excludes them. for (uint32_t n{0}; n < num_outputs - 1; ++n) { if (fuzzed_data_provider.ConsumeBool()) { - available_coins.push_front(COutPoint{tx->GetHash(), n}); + available_coins.emplace_front(tx->GetHash(), n); } else { - available_coins.push_back(COutPoint{tx->GetHash(), n}); + available_coins.emplace_back(tx->GetHash(), n); } } diff --git a/src/test/fuzz/miniscript.cpp b/src/test/fuzz/miniscript.cpp index 835b6d8c6b..6ffaa0703c 100644 --- a/src/test/fuzz/miniscript.cpp +++ b/src/test/fuzz/miniscript.cpp @@ -1017,7 +1017,7 @@ CScript ScriptPubKey(MsCtx ctx, const CScript& script, TaprootBuilder& builder) //! Fill the witness with the data additional to the script satisfaction. void SatisfactionToWitness(MsCtx ctx, CScriptWitness& witness, const CScript& script, TaprootBuilder& builder) { // For P2WSH, it's only the witness script. - witness.stack.push_back(std::vector(script.begin(), script.end())); + witness.stack.emplace_back(script.begin(), script.end()); if (!miniscript::IsTapscript(ctx)) return; // For Tapscript we also need the control block. witness.stack.push_back(*builder.GetSpendData().scripts.begin()->second.begin()); diff --git a/src/test/headers_sync_chainwork_tests.cpp b/src/test/headers_sync_chainwork_tests.cpp index 41241ebee2..b710ad1801 100644 --- a/src/test/headers_sync_chainwork_tests.cpp +++ b/src/test/headers_sync_chainwork_tests.cpp @@ -40,7 +40,7 @@ void HeadersGeneratorSetup::GenerateHeaders(std::vector& headers, uint256 prev_hash = starting_hash; while (headers.size() < count) { - headers.push_back(CBlockHeader()); + headers.emplace_back(); CBlockHeader& next_header = headers.back();; next_header.nVersion = nVersion; next_header.hashPrevBlock = prev_hash; diff --git a/src/test/miniscript_tests.cpp b/src/test/miniscript_tests.cpp index c8a39076e2..5c70678fd1 100644 --- a/src/test/miniscript_tests.cpp +++ b/src/test/miniscript_tests.cpp @@ -337,7 +337,7 @@ CScript ScriptPubKey(miniscript::MiniscriptContext ctx, const CScript& script, T //! Fill the witness with the data additional to the script satisfaction. void SatisfactionToWitness(miniscript::MiniscriptContext ctx, CScriptWitness& witness, const CScript& script, TaprootBuilder& builder) { // For P2WSH, it's only the witness script. - witness.stack.push_back(std::vector(script.begin(), script.end())); + witness.stack.emplace_back(script.begin(), script.end()); if (!miniscript::IsTapscript(ctx)) return; // For Tapscript we also need the control block. witness.stack.push_back(*builder.GetSpendData().scripts.begin()->second.begin()); diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp index 5976aa3713..796716d6cb 100644 --- a/src/test/net_tests.cpp +++ b/src/test/net_tests.cpp @@ -1080,9 +1080,9 @@ public: bool reject{false}; auto msg = m_transport.GetReceivedMessage({}, reject); if (reject) { - ret.push_back(std::nullopt); + ret.emplace_back(std::nullopt); } else { - ret.push_back(std::move(msg)); + ret.emplace_back(std::move(msg)); } progress = true; } diff --git a/src/test/rbf_tests.cpp b/src/test/rbf_tests.cpp index 10205cd641..fb6a3614c0 100644 --- a/src/test/rbf_tests.cpp +++ b/src/test/rbf_tests.cpp @@ -27,7 +27,7 @@ static inline CTransactionRef make_tx(const std::vector& inputs tx.vin[i].prevout.n = 0; // Add a witness so wtxid != txid CScriptWitness witness; - witness.stack.push_back(std::vector(i + 10)); + witness.stack.emplace_back(i + 10); tx.vin[i].scriptWitness = witness; } for (size_t i = 0; i < output_values.size(); ++i) { diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp index 4cad3ec68e..0d2460c606 100644 --- a/src/test/rpc_tests.cpp +++ b/src/test/rpc_tests.cpp @@ -428,11 +428,11 @@ BOOST_AUTO_TEST_CASE(rpc_getblockstats_calculate_percentiles_by_weight) CAmount result[NUM_GETBLOCKSTATS_PERCENTILES] = { 0 }; for (int64_t i = 0; i < 100; i++) { - feerates.emplace_back(std::make_pair(1 ,1)); + feerates.emplace_back(1 ,1); } for (int64_t i = 0; i < 100; i++) { - feerates.emplace_back(std::make_pair(2 ,1)); + feerates.emplace_back(2 ,1); } CalculatePercentilesByWeight(result, feerates, total_weight); @@ -447,11 +447,11 @@ BOOST_AUTO_TEST_CASE(rpc_getblockstats_calculate_percentiles_by_weight) CAmount result2[NUM_GETBLOCKSTATS_PERCENTILES] = { 0 }; feerates.clear(); - feerates.emplace_back(std::make_pair(1, 9)); - feerates.emplace_back(std::make_pair(2 , 16)); //10th + 25th percentile - feerates.emplace_back(std::make_pair(4 ,50)); //50th + 75th percentile - feerates.emplace_back(std::make_pair(5 ,10)); - feerates.emplace_back(std::make_pair(9 ,15)); // 90th percentile + feerates.emplace_back(1, 9); + feerates.emplace_back(2 , 16); //10th + 25th percentile + feerates.emplace_back(4 ,50); //50th + 75th percentile + feerates.emplace_back(5 ,10); + feerates.emplace_back(9 ,15); // 90th percentile CalculatePercentilesByWeight(result2, feerates, total_weight); @@ -466,12 +466,12 @@ BOOST_AUTO_TEST_CASE(rpc_getblockstats_calculate_percentiles_by_weight) CAmount result3[NUM_GETBLOCKSTATS_PERCENTILES] = { 0 }; feerates.clear(); - feerates.emplace_back(std::make_pair(1, 9)); - feerates.emplace_back(std::make_pair(2 , 11)); // 10th percentile - feerates.emplace_back(std::make_pair(2 , 5)); // 25th percentile - feerates.emplace_back(std::make_pair(4 ,50)); //50th + 75th percentile - feerates.emplace_back(std::make_pair(5 ,10)); - feerates.emplace_back(std::make_pair(9 ,15)); // 90th percentile + feerates.emplace_back(1, 9); + feerates.emplace_back(2 , 11); // 10th percentile + feerates.emplace_back(2 , 5); // 25th percentile + feerates.emplace_back(4 ,50); //50th + 75th percentile + feerates.emplace_back(5 ,10); + feerates.emplace_back(9 ,15); // 90th percentile CalculatePercentilesByWeight(result3, feerates, total_weight); @@ -486,11 +486,11 @@ BOOST_AUTO_TEST_CASE(rpc_getblockstats_calculate_percentiles_by_weight) CAmount result4[NUM_GETBLOCKSTATS_PERCENTILES] = { 0 }; feerates.clear(); - feerates.emplace_back(std::make_pair(1, 100)); - feerates.emplace_back(std::make_pair(2, 1)); - feerates.emplace_back(std::make_pair(3, 1)); - feerates.emplace_back(std::make_pair(3, 1)); - feerates.emplace_back(std::make_pair(999999, 1)); + feerates.emplace_back(1, 100); + feerates.emplace_back(2, 1); + feerates.emplace_back(3, 1); + feerates.emplace_back(3, 1); + feerates.emplace_back(999999, 1); CalculatePercentilesByWeight(result4, feerates, total_weight); @@ -506,7 +506,7 @@ BOOST_AUTO_TEST_CASE(check_dup_param_names) auto make_rpc = [](std::vector> param_names) { std::vector params; std::vector options; - auto push_options = [&] { if (!options.empty()) params.emplace_back(RPCArg{strprintf("options%i", params.size()), RPCArg::Type::OBJ_NAMED_PARAMS, RPCArg::Optional::OMITTED, "", std::move(options)}); }; + auto push_options = [&] { if (!options.empty()) params.emplace_back(strprintf("options%i", params.size()), RPCArg::Type::OBJ_NAMED_PARAMS, RPCArg::Optional::OMITTED, "", std::move(options)); }; for (auto& [param_name, param_type] : param_names) { if (param_type == POSITIONAL) { push_options(); diff --git a/src/test/settings_tests.cpp b/src/test/settings_tests.cpp index eb11df0497..fa8ceb8dd6 100644 --- a/src/test/settings_tests.cpp +++ b/src/test/settings_tests.cpp @@ -119,16 +119,16 @@ static void CheckValues(const common::Settings& settings, const std::string& sin BOOST_AUTO_TEST_CASE(Simple) { common::Settings settings; - settings.command_line_options["name"].push_back("val1"); - settings.command_line_options["name"].push_back("val2"); - settings.ro_config["section"]["name"].push_back(2); + settings.command_line_options["name"].emplace_back("val1"); + settings.command_line_options["name"].emplace_back("val2"); + settings.ro_config["section"]["name"].emplace_back(2); // The last given arg takes precedence when specified via commandline. CheckValues(settings, R"("val2")", R"(["val1","val2",2])"); common::Settings settings2; - settings2.ro_config["section"]["name"].push_back("val2"); - settings2.ro_config["section"]["name"].push_back("val3"); + settings2.ro_config["section"]["name"].emplace_back("val2"); + settings2.ro_config["section"]["name"].emplace_back("val3"); // The first given arg takes precedence when specified via config file. CheckValues(settings2, R"("val2")", R"(["val2","val3"])"); @@ -141,7 +141,7 @@ BOOST_AUTO_TEST_CASE(Simple) BOOST_AUTO_TEST_CASE(NullOverride) { common::Settings settings; - settings.command_line_options["name"].push_back("value"); + settings.command_line_options["name"].emplace_back("value"); BOOST_CHECK_EQUAL(R"("value")", GetSetting(settings, "section", "name", false, false, false).write().c_str()); settings.forced_settings["name"] = {}; BOOST_CHECK_EQUAL(R"(null)", GetSetting(settings, "section", "name", false, false, false).write().c_str()); @@ -202,11 +202,11 @@ BOOST_FIXTURE_TEST_CASE(Merge, MergeTestingSetup) std::vector& dest) { if (action == SET || action == SECTION_SET) { for (int i = 0; i < 2; ++i) { - dest.push_back(value_prefix + ToString(++value_suffix)); + dest.emplace_back(value_prefix + ToString(++value_suffix)); desc += " " + name_prefix + name + "=" + dest.back().get_str(); } } else if (action == NEGATE || action == SECTION_NEGATE) { - dest.push_back(false); + dest.emplace_back(false); desc += " " + name_prefix + "no" + name; } }; diff --git a/src/test/sighash_tests.cpp b/src/test/sighash_tests.cpp index 178b16772b..9653edd84b 100644 --- a/src/test/sighash_tests.cpp +++ b/src/test/sighash_tests.cpp @@ -100,7 +100,7 @@ void static RandomTransaction(CMutableTransaction& tx, bool fSingle) int ins = (InsecureRandBits(2)) + 1; int outs = fSingle ? ins : (InsecureRandBits(2)) + 1; for (int in = 0; in < ins; in++) { - tx.vin.push_back(CTxIn()); + tx.vin.emplace_back(); CTxIn &txin = tx.vin.back(); txin.prevout.hash = InsecureRand256(); txin.prevout.n = InsecureRandBits(2); @@ -108,7 +108,7 @@ void static RandomTransaction(CMutableTransaction& tx, bool fSingle) txin.nSequence = (InsecureRandBool()) ? InsecureRand32() : std::numeric_limits::max(); } for (int out = 0; out < outs; out++) { - tx.vout.push_back(CTxOut()); + tx.vout.emplace_back(); CTxOut &txout = tx.vout.back(); txout.nValue = InsecureRandMoneyAmount(); RandomScript(txout.scriptPubKey); diff --git a/src/test/sigopcount_tests.cpp b/src/test/sigopcount_tests.cpp index ec9490d745..c0bed50e1d 100644 --- a/src/test/sigopcount_tests.cpp +++ b/src/test/sigopcount_tests.cpp @@ -160,8 +160,8 @@ BOOST_AUTO_TEST_CASE(GetTxSigOpCost) CScript scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(pubkey)); CScript scriptSig = CScript(); CScriptWitness scriptWitness; - scriptWitness.stack.push_back(std::vector(0)); - scriptWitness.stack.push_back(std::vector(0)); + scriptWitness.stack.emplace_back(0); + scriptWitness.stack.emplace_back(0); BuildTxs(spendingTx, coins, creationTx, scriptPubKey, scriptSig, scriptWitness); @@ -189,8 +189,8 @@ BOOST_AUTO_TEST_CASE(GetTxSigOpCost) CScript scriptPubKey = GetScriptForDestination(ScriptHash(scriptSig)); scriptSig = CScript() << ToByteVector(scriptSig); CScriptWitness scriptWitness; - scriptWitness.stack.push_back(std::vector(0)); - scriptWitness.stack.push_back(std::vector(0)); + scriptWitness.stack.emplace_back(0); + scriptWitness.stack.emplace_back(0); BuildTxs(spendingTx, coins, creationTx, scriptPubKey, scriptSig, scriptWitness); assert(GetTransactionSigOpCost(CTransaction(spendingTx), coins, flags) == 1); @@ -203,9 +203,9 @@ BOOST_AUTO_TEST_CASE(GetTxSigOpCost) CScript scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(witnessScript)); CScript scriptSig = CScript(); CScriptWitness scriptWitness; - scriptWitness.stack.push_back(std::vector(0)); - scriptWitness.stack.push_back(std::vector(0)); - scriptWitness.stack.push_back(std::vector(witnessScript.begin(), witnessScript.end())); + scriptWitness.stack.emplace_back(0); + scriptWitness.stack.emplace_back(0); + scriptWitness.stack.emplace_back(witnessScript.begin(), witnessScript.end()); BuildTxs(spendingTx, coins, creationTx, scriptPubKey, scriptSig, scriptWitness); assert(GetTransactionSigOpCost(CTransaction(spendingTx), coins, flags) == 2); @@ -220,9 +220,9 @@ BOOST_AUTO_TEST_CASE(GetTxSigOpCost) CScript scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript)); CScript scriptSig = CScript() << ToByteVector(redeemScript); CScriptWitness scriptWitness; - scriptWitness.stack.push_back(std::vector(0)); - scriptWitness.stack.push_back(std::vector(0)); - scriptWitness.stack.push_back(std::vector(witnessScript.begin(), witnessScript.end())); + scriptWitness.stack.emplace_back(0); + scriptWitness.stack.emplace_back(0); + scriptWitness.stack.emplace_back(witnessScript.begin(), witnessScript.end()); BuildTxs(spendingTx, coins, creationTx, scriptPubKey, scriptSig, scriptWitness); assert(GetTransactionSigOpCost(CTransaction(spendingTx), coins, flags) == 2); diff --git a/src/test/txpackage_tests.cpp b/src/test/txpackage_tests.cpp index a8318e9fdb..4d9a5ef7f3 100644 --- a/src/test/txpackage_tests.cpp +++ b/src/test/txpackage_tests.cpp @@ -173,9 +173,9 @@ BOOST_FIXTURE_TEST_CASE(noncontextual_package_tests, TestChain100Setup) auto parent = MakeTransactionRef(CreateValidMempoolTransaction(m_coinbase_txns[i + 1], 0, 0, coinbaseKey, spk, CAmount(48 * COIN), false)); package.emplace_back(parent); - child.vin.push_back(CTxIn(COutPoint(parent->GetHash(), 0))); + child.vin.emplace_back(COutPoint(parent->GetHash(), 0)); } - child.vout.push_back(CTxOut(47 * COIN, spk2)); + child.vout.emplace_back(47 * COIN, spk2); // The child must be in the package. BOOST_CHECK(!IsChildWithParents(package)); @@ -201,20 +201,20 @@ BOOST_FIXTURE_TEST_CASE(noncontextual_package_tests, TestChain100Setup) // 2 Parents and 1 Child where one parent depends on the other. { CMutableTransaction mtx_parent; - mtx_parent.vin.push_back(CTxIn(COutPoint(m_coinbase_txns[0]->GetHash(), 0))); - mtx_parent.vout.push_back(CTxOut(20 * COIN, spk)); - mtx_parent.vout.push_back(CTxOut(20 * COIN, spk2)); + mtx_parent.vin.emplace_back(COutPoint(m_coinbase_txns[0]->GetHash(), 0)); + mtx_parent.vout.emplace_back(20 * COIN, spk); + mtx_parent.vout.emplace_back(20 * COIN, spk2); CTransactionRef tx_parent = MakeTransactionRef(mtx_parent); CMutableTransaction mtx_parent_also_child; - mtx_parent_also_child.vin.push_back(CTxIn(COutPoint(tx_parent->GetHash(), 0))); - mtx_parent_also_child.vout.push_back(CTxOut(20 * COIN, spk)); + mtx_parent_also_child.vin.emplace_back(COutPoint(tx_parent->GetHash(), 0)); + mtx_parent_also_child.vout.emplace_back(20 * COIN, spk); CTransactionRef tx_parent_also_child = MakeTransactionRef(mtx_parent_also_child); CMutableTransaction mtx_child; - mtx_child.vin.push_back(CTxIn(COutPoint(tx_parent->GetHash(), 1))); - mtx_child.vin.push_back(CTxIn(COutPoint(tx_parent_also_child->GetHash(), 0))); - mtx_child.vout.push_back(CTxOut(39 * COIN, spk)); + mtx_child.vin.emplace_back(COutPoint(tx_parent->GetHash(), 1)); + mtx_child.vin.emplace_back(COutPoint(tx_parent_also_child->GetHash(), 0)); + mtx_child.vout.emplace_back(39 * COIN, spk); CTransactionRef tx_child = MakeTransactionRef(mtx_child); PackageValidationState state; @@ -301,7 +301,7 @@ BOOST_FIXTURE_TEST_CASE(package_submission_tests, TestChain100Setup) // missing inputs, so the package validation isn't expected to happen. { CScriptWitness bad_witness; - bad_witness.stack.push_back(std::vector(1)); + bad_witness.stack.emplace_back(1); CMutableTransaction mtx_parent_invalid{mtx_parent}; mtx_parent_invalid.vin[0].scriptWitness = bad_witness; CTransactionRef tx_parent_invalid = MakeTransactionRef(mtx_parent_invalid); @@ -322,7 +322,7 @@ BOOST_FIXTURE_TEST_CASE(package_submission_tests, TestChain100Setup) } // Child with missing parent. - mtx_child.vin.push_back(CTxIn(COutPoint(package_unrelated[0]->GetHash(), 0))); + mtx_child.vin.emplace_back(COutPoint(package_unrelated[0]->GetHash(), 0)); Package package_missing_parent; package_missing_parent.push_back(tx_parent); package_missing_parent.push_back(MakeTransactionRef(mtx_child)); @@ -404,12 +404,12 @@ BOOST_FIXTURE_TEST_CASE(package_witness_swap_tests, TestChain100Setup) // Make two children with the same txid but different witnesses. CScriptWitness witness1; - witness1.stack.push_back(std::vector(1)); - witness1.stack.push_back(std::vector(witnessScript.begin(), witnessScript.end())); + witness1.stack.emplace_back(1); + witness1.stack.emplace_back(witnessScript.begin(), witnessScript.end()); CScriptWitness witness2(witness1); - witness2.stack.push_back(std::vector(2)); - witness2.stack.push_back(std::vector(witnessScript.begin(), witnessScript.end())); + witness2.stack.emplace_back(2); + witness2.stack.emplace_back(witnessScript.begin(), witnessScript.end()); CKey child_key; child_key.MakeNewKey(true); @@ -529,7 +529,7 @@ BOOST_FIXTURE_TEST_CASE(package_witness_swap_tests, TestChain100Setup) CScript acs_script = CScript() << OP_TRUE; CScript acs_spk = GetScriptForDestination(WitnessV0ScriptHash(acs_script)); CScriptWitness acs_witness; - acs_witness.stack.push_back(std::vector(acs_script.begin(), acs_script.end())); + acs_witness.stack.emplace_back(acs_script.begin(), acs_script.end()); // parent1 will already be in the mempool auto mtx_parent1 = CreateValidMempoolTransaction(/*input_transaction=*/m_coinbase_txns[1], /*input_vout=*/0, @@ -543,11 +543,11 @@ BOOST_FIXTURE_TEST_CASE(package_witness_swap_tests, TestChain100Setup) CScript grandparent2_script = CScript() << OP_DROP << OP_TRUE; CScript grandparent2_spk = GetScriptForDestination(WitnessV0ScriptHash(grandparent2_script)); CScriptWitness parent2_witness1; - parent2_witness1.stack.push_back(std::vector(1)); - parent2_witness1.stack.push_back(std::vector(grandparent2_script.begin(), grandparent2_script.end())); + parent2_witness1.stack.emplace_back(1); + parent2_witness1.stack.emplace_back(grandparent2_script.begin(), grandparent2_script.end()); CScriptWitness parent2_witness2; - parent2_witness2.stack.push_back(std::vector(2)); - parent2_witness2.stack.push_back(std::vector(grandparent2_script.begin(), grandparent2_script.end())); + parent2_witness2.stack.emplace_back(2); + parent2_witness2.stack.emplace_back(grandparent2_script.begin(), grandparent2_script.end()); // Create grandparent2 creating an output with multiple spending paths. Submit to mempool. auto mtx_grandparent2 = CreateValidMempoolTransaction(/*input_transaction=*/m_coinbase_txns[2], /*input_vout=*/0, @@ -593,13 +593,13 @@ BOOST_FIXTURE_TEST_CASE(package_witness_swap_tests, TestChain100Setup) CScript mixed_child_spk = GetScriptForDestination(WitnessV0KeyHash(mixed_grandchild_key.GetPubKey())); CMutableTransaction mtx_mixed_child; - mtx_mixed_child.vin.push_back(CTxIn(COutPoint(ptx_parent1->GetHash(), 0))); - mtx_mixed_child.vin.push_back(CTxIn(COutPoint(ptx_parent2_v1->GetHash(), 0))); - mtx_mixed_child.vin.push_back(CTxIn(COutPoint(ptx_parent3->GetHash(), 0))); + mtx_mixed_child.vin.emplace_back(COutPoint(ptx_parent1->GetHash(), 0)); + mtx_mixed_child.vin.emplace_back(COutPoint(ptx_parent2_v1->GetHash(), 0)); + mtx_mixed_child.vin.emplace_back(COutPoint(ptx_parent3->GetHash(), 0)); mtx_mixed_child.vin[0].scriptWitness = acs_witness; mtx_mixed_child.vin[1].scriptWitness = acs_witness; mtx_mixed_child.vin[2].scriptWitness = acs_witness; - mtx_mixed_child.vout.push_back(CTxOut((48 + 49 + 50 - 1) * COIN, mixed_child_spk)); + mtx_mixed_child.vout.emplace_back((48 + 49 + 50 - 1) * COIN, mixed_child_spk); CTransactionRef ptx_mixed_child = MakeTransactionRef(mtx_mixed_child); package_mixed.push_back(ptx_mixed_child); diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index e27d5a27ad..e70c105c8a 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -400,7 +400,7 @@ std::vector TestChain100Setup::PopulateMempool(FastRandomContex for (size_t n{0}; n < num_inputs; ++n) { if (unspent_prevouts.empty()) break; const auto& [prevout, amount] = unspent_prevouts.front(); - mtx.vin.push_back(CTxIn(prevout, CScript())); + mtx.vin.emplace_back(prevout, CScript()); total_in += amount; unspent_prevouts.pop_front(); } @@ -409,7 +409,7 @@ std::vector TestChain100Setup::PopulateMempool(FastRandomContex const CAmount amount_per_output = (total_in - fee) / num_outputs; for (size_t n{0}; n < num_outputs; ++n) { CScript spk = CScript() << CScriptNum(num_transactions + n); - mtx.vout.push_back(CTxOut(amount_per_output, spk)); + mtx.vout.emplace_back(amount_per_output, spk); } CTransactionRef ptx = MakeTransactionRef(mtx); mempool_transactions.push_back(ptx); @@ -418,7 +418,7 @@ std::vector TestChain100Setup::PopulateMempool(FastRandomContex // it can be used to build a more complex transaction graph. Insert randomly into // unspent_prevouts for extra randomness in the resulting structures. for (size_t n{0}; n < num_outputs; ++n) { - unspent_prevouts.push_back(std::make_pair(COutPoint(ptx->GetHash(), n), amount_per_output)); + unspent_prevouts.emplace_back(COutPoint(ptx->GetHash(), n), amount_per_output); std::swap(unspent_prevouts.back(), unspent_prevouts[det_rand.randrange(unspent_prevouts.size())]); } } @@ -448,8 +448,8 @@ void TestChain100Setup::MockMempoolMinFee(const CFeeRate& target_feerate) // Manually create an invalid transaction. Manually set the fee in the CTxMemPoolEntry to // achieve the exact target feerate. CMutableTransaction mtx = CMutableTransaction(); - mtx.vin.push_back(CTxIn{COutPoint{g_insecure_rand_ctx.rand256(), 0}}); - mtx.vout.push_back(CTxOut(1 * COIN, GetScriptForDestination(WitnessV0ScriptHash(CScript() << OP_TRUE)))); + mtx.vin.emplace_back(COutPoint{g_insecure_rand_ctx.rand256(), 0}); + mtx.vout.emplace_back(1 * COIN, GetScriptForDestination(WitnessV0ScriptHash(CScript() << OP_TRUE))); const auto tx{MakeTransactionRef(mtx)}; LockPoints lp; // The new mempool min feerate is equal to the removed package's feerate + incremental feerate. diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index 67f71bd266..7d6c96ab40 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -1023,9 +1023,9 @@ BOOST_AUTO_TEST_CASE(test_FormatParagraph) BOOST_AUTO_TEST_CASE(test_FormatSubVersion) { std::vector comments; - comments.push_back(std::string("comment1")); + comments.emplace_back("comment1"); std::vector comments2; - comments2.push_back(std::string("comment1")); + comments2.emplace_back("comment1"); comments2.push_back(SanitizeString(std::string("Comment2; .,_?@-; !\"#$%&'()*+/<=>[]\\^`{|}~"), SAFE_CHARS_UA_COMMENT)); // Semicolon is discouraged but not forbidden by BIP-0014 BOOST_CHECK_EQUAL(FormatSubVersion("Test", 99900, std::vector()),std::string("/Test:9.99.0/")); BOOST_CHECK_EQUAL(FormatSubVersion("Test", 99900, comments),std::string("/Test:9.99.0(comment1)/")); diff --git a/src/test/util_threadnames_tests.cpp b/src/test/util_threadnames_tests.cpp index ae913939e8..45d3a58fd3 100644 --- a/src/test/util_threadnames_tests.cpp +++ b/src/test/util_threadnames_tests.cpp @@ -40,7 +40,7 @@ std::set RenameEnMasse(int num_threads) threads.reserve(num_threads); for (int i = 0; i < num_threads; ++i) { - threads.push_back(std::thread(RenameThisThread, i)); + threads.emplace_back(RenameThisThread, i); } for (std::thread& thread : threads) thread.join(); diff --git a/src/test/validation_block_tests.cpp b/src/test/validation_block_tests.cpp index 411371f7c1..64cb5522eb 100644 --- a/src/test/validation_block_tests.cpp +++ b/src/test/validation_block_tests.cpp @@ -117,7 +117,7 @@ std::shared_ptr MinerTestingSetup::BadBlock(const uint256& prev_ha auto pblock = Block(prev_hash); CMutableTransaction coinbase_spend; - coinbase_spend.vin.push_back(CTxIn(COutPoint(pblock->vtx[0]->GetHash(), 0), CScript(), 0)); + coinbase_spend.vin.emplace_back(COutPoint(pblock->vtx[0]->GetHash(), 0), CScript(), 0); coinbase_spend.vout.push_back(pblock->vtx[0]->vout[0]); CTransactionRef tx = MakeTransactionRef(coinbase_spend); @@ -245,7 +245,7 @@ BOOST_AUTO_TEST_CASE(mempool_locks_reorg) std::vector txs; for (int num_txs = 22; num_txs > 0; --num_txs) { CMutableTransaction mtx; - mtx.vin.push_back(CTxIn{COutPoint{last_mined->vtx[0]->GetHash(), 1}, CScript{}}); + mtx.vin.emplace_back(COutPoint{last_mined->vtx[0]->GetHash(), 1}, CScript{}); mtx.vin[0].scriptWitness.stack.push_back(WITNESS_STACK_ELEM_OP_TRUE); mtx.vout.push_back(last_mined->vtx[0]->vout[1]); mtx.vout[0].nValue -= 1000; diff --git a/src/txmempool.cpp b/src/txmempool.cpp index e021cfb06e..461662ad93 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -1021,7 +1021,7 @@ void CCoinsViewMemPool::PackageAddTransaction(const CTransactionRef& tx) { for (unsigned int n = 0; n < tx->vout.size(); ++n) { m_temp_added.emplace(COutPoint(tx->GetHash(), n), Coin(tx->vout[n], MEMPOOL_HEIGHT, false)); - m_non_base_coins.emplace(COutPoint(tx->GetHash(), n)); + m_non_base_coins.emplace(tx->GetHash(), n); } } void CCoinsViewMemPool::Reset() diff --git a/src/validation.cpp b/src/validation.cpp index 9108f911f0..290db8c9b2 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2413,7 +2413,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state, CTxUndo undoDummy; if (i > 0) { - blockundo.vtxundo.push_back(CTxUndo()); + blockundo.vtxundo.emplace_back(); } UpdateCoins(tx, view, i == 0 ? undoDummy : blockundo.vtxundo.back(), pindex->nHeight); } diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp index d100b69d3c..3e1ec667e0 100644 --- a/src/wallet/rpc/backup.cpp +++ b/src/wallet/rpc/backup.cpp @@ -573,13 +573,13 @@ RPCHelpMan importwallet() } } nTimeBegin = std::min(nTimeBegin, nTime); - keys.push_back(std::make_tuple(key, nTime, fLabel, strLabel)); + keys.emplace_back(key, nTime, fLabel, strLabel); } else if(IsHex(vstr[0])) { std::vector vData(ParseHex(vstr[0])); CScript script = CScript(vData.begin(), vData.end()); int64_t birth_time = ParseISO8601DateTime(vstr[1]); if (birth_time > 0) nTimeBegin = std::min(nTimeBegin, birth_time); - scripts.push_back(std::pair(script, birth_time)); + scripts.emplace_back(script, birth_time); } } file.close(); @@ -759,7 +759,7 @@ RPCHelpMan dumpwallet() std::vector > vKeyBirth; vKeyBirth.reserve(mapKeyBirth.size()); for (const auto& entry : mapKeyBirth) { - vKeyBirth.push_back(std::make_pair(entry.second, entry.first)); + vKeyBirth.emplace_back(entry.second, entry.first); } mapKeyBirth.clear(); std::sort(vKeyBirth.begin(), vKeyBirth.end()); diff --git a/src/wallet/salvage.cpp b/src/wallet/salvage.cpp index 0a0745b1c5..04c02b0dcc 100644 --- a/src/wallet/salvage.cpp +++ b/src/wallet/salvage.cpp @@ -146,7 +146,7 @@ bool RecoverDatabaseFile(const ArgsManager& args, const fs::path& file_path, bil warnings.push_back(Untranslated("Salvage: WARNING: Number of keys in data does not match number of values.")); break; } - salvagedData.push_back(make_pair(ParseHex(keyHex), ParseHex(valueHex))); + salvagedData.emplace_back(ParseHex(keyHex), ParseHex(valueHex)); } } diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 20f735da12..bc3327cdb2 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -1902,7 +1902,7 @@ std::optional LegacyScriptPubKeyMan::MigrateToDescriptor() std::string desc_str; bool watchonly = !desc->ToPrivateString(*this, desc_str); if (watchonly && !m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { - out.watch_descs.push_back({desc->ToString(), creation_time}); + out.watch_descs.emplace_back(desc->ToString(), creation_time); // Get the scriptPubKeys without writing this to the wallet FlatSigningProvider provider; @@ -1971,14 +1971,14 @@ std::optional LegacyScriptPubKeyMan::MigrateToDescriptor() assert(IsMine(sh_spk) == ISMINE_NO && IsMine(witprog) == ISMINE_NO && IsMine(sh_wsh_spk) == ISMINE_NO); std::unique_ptr sh_desc = InferDescriptor(sh_spk, *GetSolvingProvider(sh_spk)); - out.solvable_descs.push_back({sh_desc->ToString(), creation_time}); + out.solvable_descs.emplace_back(sh_desc->ToString(), creation_time); const auto desc = InferDescriptor(witprog, *this); if (desc->IsSolvable()) { std::unique_ptr wsh_desc = InferDescriptor(witprog, *GetSolvingProvider(witprog)); - out.solvable_descs.push_back({wsh_desc->ToString(), creation_time}); + out.solvable_descs.emplace_back(wsh_desc->ToString(), creation_time); std::unique_ptr sh_wsh_desc = InferDescriptor(sh_wsh_spk, *GetSolvingProvider(sh_wsh_spk)); - out.solvable_descs.push_back({sh_wsh_desc->ToString(), creation_time}); + out.solvable_descs.emplace_back(sh_wsh_desc->ToString(), creation_time); } } } diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 7e6fba33aa..8314a2ddfa 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -1151,7 +1151,7 @@ static util::Result CreateTransactionInternal( // behavior." const uint32_t nSequence{coin_control.m_signal_bip125_rbf.value_or(wallet.m_signal_rbf) ? MAX_BIP125_RBF_SEQUENCE : CTxIn::MAX_SEQUENCE_NONFINAL}; for (const auto& coin : selected_coins) { - txNew.vin.push_back(CTxIn(coin->outpoint, CScript(), nSequence)); + txNew.vin.emplace_back(coin->outpoint, CScript(), nSequence); } DiscourageFeeSniping(txNew, rng_fast, wallet.chain(), wallet.GetLastBlockHash(), wallet.GetLastBlockHeight()); diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp index 21ed52731a..ad4bb3a9d2 100644 --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -49,7 +49,7 @@ BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup) static CMutableTransaction TestSimpleSpend(const CTransaction& from, uint32_t index, const CKey& key, const CScript& pubkey) { CMutableTransaction mtx; - mtx.vout.push_back({from.vout[index].nValue - DEFAULT_TRANSACTION_MAXFEE, pubkey}); + mtx.vout.emplace_back(from.vout[index].nValue - DEFAULT_TRANSACTION_MAXFEE, pubkey); mtx.vin.push_back({CTxIn{from.GetHash(), index}}); FillableSigningProvider keystore; keystore.AddKey(key); @@ -945,8 +945,8 @@ BOOST_FIXTURE_TEST_CASE(wallet_sync_tx_invalid_state_test, TestingSetup) const auto op_dest{*Assert(wallet.GetNewDestination(OutputType::BECH32M, ""))}; CMutableTransaction mtx; - mtx.vout.push_back({COIN, GetScriptForDestination(op_dest)}); - mtx.vin.push_back(CTxIn(g_insecure_rand_ctx.rand256(), 0)); + mtx.vout.emplace_back(COIN, GetScriptForDestination(op_dest)); + mtx.vin.emplace_back(g_insecure_rand_ctx.rand256(), 0); const auto& tx_id_to_spend = wallet.AddToWallet(MakeTransactionRef(mtx), TxStateInMempool{})->GetHash(); { @@ -961,7 +961,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_sync_tx_invalid_state_test, TestingSetup) // 2) Verify that the available balance of this new tx and the old one is updated (prev tx is marked dirty) mtx.vin.clear(); - mtx.vin.push_back(CTxIn(tx_id_to_spend, 0)); + mtx.vin.emplace_back(tx_id_to_spend, 0); wallet.transactionAddedToMempool(MakeTransactionRef(mtx)); const uint256& good_tx_id = mtx.GetHash(); @@ -982,7 +982,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_sync_tx_invalid_state_test, TestingSetup) // verify that we are not moving forward if the wallet cannot store it GetMockableDatabase(wallet).m_pass = false; mtx.vin.clear(); - mtx.vin.push_back(CTxIn(good_tx_id, 0)); + mtx.vin.emplace_back(good_tx_id, 0); BOOST_CHECK_EXCEPTION(wallet.transactionAddedToMempool(MakeTransactionRef(mtx)), std::runtime_error, HasReason("DB error adding transaction to wallet, write failed")); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c240e88531..5d2f9e2fb6 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4230,7 +4230,7 @@ util::Result MigrateLegacyToDescriptor(const std::string& walle // Remember this wallet's walletdir to remove after unloading std::vector wallet_dirs; - wallet_dirs.push_back(fs::PathFromString(local_wallet->GetDatabase().Filename()).parent_path()); + wallet_dirs.emplace_back(fs::PathFromString(local_wallet->GetDatabase().Filename()).parent_path()); // Unload the wallet locally assert(local_wallet.use_count() == 1); @@ -4243,7 +4243,7 @@ util::Result MigrateLegacyToDescriptor(const std::string& walle // Get the directories to remove after unloading for (std::shared_ptr& w : created_wallets) { - wallet_dirs.push_back(fs::PathFromString(w->GetDatabase().Filename()).parent_path()); + wallet_dirs.emplace_back(fs::PathFromString(w->GetDatabase().Filename()).parent_path()); } // Unload the wallets