mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-29 05:22:30 +02:00
rpc: reserve space for UniValue
variables in blockToJSON
- Reserving space avoid reallocation, this provide noticeable performance increase in verbosity level 1, 2. Github-Pull: #31179 Rebased-From: 28e3392d11355b1160dc1a7a5557081728a02840
This commit is contained in:
parent
1c894b355e
commit
5dcab5edf5
@ -183,6 +183,7 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry
|
|||||||
entry.pushKV("locktime", (int64_t)tx.nLockTime);
|
entry.pushKV("locktime", (int64_t)tx.nLockTime);
|
||||||
|
|
||||||
UniValue vin{UniValue::VARR};
|
UniValue vin{UniValue::VARR};
|
||||||
|
vin.reserve(tx.vin.size());
|
||||||
|
|
||||||
// If available, use Undo data to calculate the fee. Note that txundo == nullptr
|
// If available, use Undo data to calculate the fee. Note that txundo == nullptr
|
||||||
// for coinbase transactions and for transactions where undo data is unavailable.
|
// for coinbase transactions and for transactions where undo data is unavailable.
|
||||||
@ -205,6 +206,7 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry
|
|||||||
}
|
}
|
||||||
if (!tx.vin[i].scriptWitness.IsNull()) {
|
if (!tx.vin[i].scriptWitness.IsNull()) {
|
||||||
UniValue txinwitness(UniValue::VARR);
|
UniValue txinwitness(UniValue::VARR);
|
||||||
|
txinwitness.reserve(tx.vin[i].scriptWitness.stack.size());
|
||||||
for (const auto& item : tx.vin[i].scriptWitness.stack) {
|
for (const auto& item : tx.vin[i].scriptWitness.stack) {
|
||||||
txinwitness.push_back(HexStr(item));
|
txinwitness.push_back(HexStr(item));
|
||||||
}
|
}
|
||||||
@ -234,6 +236,7 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry
|
|||||||
entry.pushKV("vin", vin);
|
entry.pushKV("vin", vin);
|
||||||
|
|
||||||
UniValue vout(UniValue::VARR);
|
UniValue vout(UniValue::VARR);
|
||||||
|
vout.reserve(tx.vout.size());
|
||||||
for (unsigned int i = 0; i < tx.vout.size(); i++) {
|
for (unsigned int i = 0; i < tx.vout.size(); i++) {
|
||||||
const CTxOut& txout = tx.vout[i];
|
const CTxOut& txout = tx.vout[i];
|
||||||
|
|
||||||
|
@ -171,6 +171,7 @@ UniValue blockToJSON(BlockManager& blockman, const CBlock& block, const CBlockIn
|
|||||||
result.pushKV("size", (int)::GetSerializeSize(block, PROTOCOL_VERSION));
|
result.pushKV("size", (int)::GetSerializeSize(block, PROTOCOL_VERSION));
|
||||||
result.pushKV("weight", (int)::GetBlockWeight(block));
|
result.pushKV("weight", (int)::GetBlockWeight(block));
|
||||||
UniValue txs(UniValue::VARR);
|
UniValue txs(UniValue::VARR);
|
||||||
|
txs.reserve(block.vtx.size());
|
||||||
|
|
||||||
switch (verbosity) {
|
switch (verbosity) {
|
||||||
case TxVerbosity::SHOW_TXID:
|
case TxVerbosity::SHOW_TXID:
|
||||||
|
Loading…
Reference in New Issue
Block a user