mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-07 11:39:01 +02:00
Merge 5d82d92aff7c11ce17ee809c060e37f73a8a687a into db2c57ae9eebdb75c58cd165ac929919969c19a9
This commit is contained in:
commit
37d166ec88
@ -45,17 +45,34 @@ struct TestBlockAndIndex {
|
||||
|
||||
} // namespace
|
||||
|
||||
static void BlockToJsonVerbose(benchmark::Bench& bench)
|
||||
static void BlockToJson(benchmark::Bench& bench, TxVerbosity verbosity)
|
||||
{
|
||||
TestBlockAndIndex data;
|
||||
const uint256 pow_limit{data.testing_setup->m_node.chainman->GetParams().GetConsensus().powLimit};
|
||||
bench.run([&] {
|
||||
auto univalue = blockToJSON(data.testing_setup->m_node.chainman->m_blockman, data.block, data.blockindex, data.blockindex, TxVerbosity::SHOW_DETAILS_AND_PREVOUT, pow_limit);
|
||||
auto univalue = blockToJSON(data.testing_setup->m_node.chainman->m_blockman, data.block, data.blockindex, data.blockindex, verbosity, pow_limit);
|
||||
ankerl::nanobench::doNotOptimizeAway(univalue);
|
||||
});
|
||||
}
|
||||
|
||||
BENCHMARK(BlockToJsonVerbose, benchmark::PriorityLevel::HIGH);
|
||||
static void BlockToJsonVerbosity1(benchmark::Bench& bench)
|
||||
{
|
||||
BlockToJson(bench, TxVerbosity::SHOW_TXID);
|
||||
}
|
||||
|
||||
static void BlockToJsonVerbosity2(benchmark::Bench& bench)
|
||||
{
|
||||
BlockToJson(bench, TxVerbosity::SHOW_DETAILS);
|
||||
}
|
||||
|
||||
static void BlockToJsonVerbosity3(benchmark::Bench& bench)
|
||||
{
|
||||
BlockToJson(bench, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);
|
||||
}
|
||||
|
||||
BENCHMARK(BlockToJsonVerbosity1, benchmark::PriorityLevel::HIGH);
|
||||
BENCHMARK(BlockToJsonVerbosity2, benchmark::PriorityLevel::HIGH);
|
||||
BENCHMARK(BlockToJsonVerbosity3, benchmark::PriorityLevel::HIGH);
|
||||
|
||||
static void BlockToJsonVerboseWrite(benchmark::Bench& bench)
|
||||
{
|
||||
|
@ -181,6 +181,7 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry
|
||||
entry.pushKV("locktime", (int64_t)tx.nLockTime);
|
||||
|
||||
UniValue vin{UniValue::VARR};
|
||||
vin.reserve(tx.vin.size());
|
||||
|
||||
// If available, use Undo data to calculate the fee. Note that txundo == nullptr
|
||||
// for coinbase transactions and for transactions where undo data is unavailable.
|
||||
@ -203,6 +204,7 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry
|
||||
}
|
||||
if (!tx.vin[i].scriptWitness.IsNull()) {
|
||||
UniValue txinwitness(UniValue::VARR);
|
||||
txinwitness.reserve(tx.vin[i].scriptWitness.stack.size());
|
||||
for (const auto& item : tx.vin[i].scriptWitness.stack) {
|
||||
txinwitness.push_back(HexStr(item));
|
||||
}
|
||||
@ -232,6 +234,7 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry
|
||||
entry.pushKV("vin", std::move(vin));
|
||||
|
||||
UniValue vout(UniValue::VARR);
|
||||
vout.reserve(tx.vout.size());
|
||||
for (unsigned int i = 0; i < tx.vout.size(); i++) {
|
||||
const CTxOut& txout = tx.vout[i];
|
||||
|
||||
|
@ -184,6 +184,7 @@ UniValue blockToJSON(BlockManager& blockman, const CBlock& block, const CBlockIn
|
||||
result.pushKV("size", (int)::GetSerializeSize(TX_WITH_WITNESS(block)));
|
||||
result.pushKV("weight", (int)::GetBlockWeight(block));
|
||||
UniValue txs(UniValue::VARR);
|
||||
txs.reserve(block.vtx.size());
|
||||
|
||||
switch (verbosity) {
|
||||
case TxVerbosity::SHOW_TXID:
|
||||
|
@ -70,6 +70,8 @@ public:
|
||||
|
||||
size_t size() const { return values.size(); }
|
||||
|
||||
void reserve(size_t new_cap);
|
||||
|
||||
void getObjMap(std::map<std::string,UniValue>& kv) const;
|
||||
bool checkObject(const std::map<std::string,UniValue::VType>& memberTypes) const;
|
||||
const UniValue& operator[](const std::string& key) const;
|
||||
|
@ -240,3 +240,10 @@ const UniValue& UniValue::find_value(std::string_view key) const
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
void UniValue::reserve(size_t new_cap)
|
||||
{
|
||||
values.reserve(new_cap);
|
||||
if (typ == VOBJ) {
|
||||
keys.reserve(new_cap);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user