aboutsummaryrefslogtreecommitdiff
path: root/src/test/fuzz
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-10-16 14:56:54 +0100
committerfanquake <fanquake@gmail.com>2023-10-16 15:35:50 +0100
commit08ea835220baa88a0e226eff90f66bbae3eb7a0f (patch)
treed8760ac8bc90b3524abac8f8fa13f11cd8d83633 /src/test/fuzz
parent92704535f66976c09a658348e554d47b7f7bcf6e (diff)
parentfa05a726c225dc65dee79367bb67f099ae4f99e6 (diff)
Merge bitcoin/bitcoin#28583: refactor: [tidy] modernize-use-emplace
fa05a726c225dc65dee79367bb67f099ae4f99e6 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 fa05a726c2 hebasto: ACK fa05a726c225dc65dee79367bb67f099ae4f99e6. TheCharlatan: ACK fa05a726c225dc65dee79367bb67f099ae4f99e6 Tree-SHA512: 4408a094f406e7bf6c1468c2b0798f68f4d952a1253cf5b20bdc648ad7eea4a2c070051fed46d66fd37bce2ce6f85962484a1d32826b7ab8c9baba431eaa2765
Diffstat (limited to 'src/test/fuzz')
-rw-r--r--src/test/fuzz/mini_miner.cpp20
-rw-r--r--src/test/fuzz/miniscript.cpp2
2 files changed, 11 insertions, 11 deletions
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<const TestingSetup>();
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<size_t>(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<size_t>(0, tx->vout.size())});
+ outpoints.emplace_back(tx->GetHash(),
+ (uint32_t)fuzzed_data_provider.ConsumeIntegralInRange<size_t>(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<size_t>(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 4d054d7458..1c4596b6fc 100644
--- a/src/test/fuzz/miniscript.cpp
+++ b/src/test/fuzz/miniscript.cpp
@@ -1015,7 +1015,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<unsigned char>(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());