bench: Construct CTxOut and COutPoint in a single expression

Replace separate member assignments with construction, using brace
initialization so the size_t to CAmount conversions have to be explicit.
Use uint32_t for the loop index feeding COutPoint::n, which avoids
conversion entirely.
This commit is contained in:
Alexander Wiederin
2026-08-19 10:22:42 +02:00
parent 59224b66aa
commit 950bdb763e
2 changed files with 4 additions and 8 deletions

View File

@@ -88,9 +88,7 @@ static void BlockEncodingBench(benchmark::Bench& bench, size_t n_pool, size_t n_
tx.vin.resize(1);
tx.vin[0].scriptSig = CScript() << sigspam;
tx.vin[0].scriptWitness.stack.push_back({1});
tx.vout.resize(1);
tx.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL;
tx.vout[0].nValue = i;
tx.vout = {CTxOut{CAmount(i), CScript() << OP_1 << OP_EQUAL}};
refs.push_back(MakeTransactionRef(tx));
}

View File

@@ -50,9 +50,8 @@ static void MempoolCheckEphemeralSpends(benchmark::Bench& bench)
tx1.vin.resize(1);
tx1.vout.resize(number_outputs);
for (size_t i = 0; i < tx1.vout.size(); i++) {
tx1.vout[i].scriptPubKey = CScript();
// Each output progressively larger
tx1.vout[i].nValue = i * CENT;
tx1.vout[i] = CTxOut{CAmount(i) * CENT, CScript()};
}
const auto& parent_txid = tx1.GetHash();
@@ -60,9 +59,8 @@ static void MempoolCheckEphemeralSpends(benchmark::Bench& bench)
// Spends all outputs of tx1, other details don't matter
CMutableTransaction tx2;
tx2.vin.resize(tx1.vout.size());
for (size_t i = 0; i < tx2.vin.size(); i++) {
tx2.vin[i].prevout.hash = parent_txid;
tx2.vin[i].prevout.n = i;
for (uint32_t i{0}; i < tx2.vin.size(); ++i) {
tx2.vin[i].prevout = COutPoint{parent_txid, i};
}
tx2.vout.resize(1);