aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2014-09-20 05:08:10 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2014-09-20 05:11:09 +0200
commit25308337d659108e3320257fb6c1c16d5fe24aa9 (patch)
tree9222a35ecf2c5628ccfd010f79c40c9123db5eb2
parent2fc6c67400e91846ca1c1c57011e57491013f9bd (diff)
parentab15b2ec71da7a82b1b08d09c0252582668a2a60 (diff)
downloadbitcoin-25308337d659108e3320257fb6c1c16d5fe24aa9.tar.xz
Merge pull request #4835
ab15b2e Avoid copying undo data (Pieter Wuille)
-rw-r--r--src/main.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 6c1c7166a8..15c3916a6f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1351,12 +1351,13 @@ void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCach
bool ret;
// mark inputs spent
if (!tx.IsCoinBase()) {
- BOOST_FOREACH(const CTxIn &txin, tx.vin) {
+ txundo.vprevout.reserve(tx.vin.size());
+ for (unsigned int i = 0; i < tx.vin.size(); i++) {
+ const CTxIn &txin = tx.vin[i];
CCoins &coins = inputs.GetCoins(txin.prevout.hash);
- CTxInUndo undo;
- ret = coins.Spend(txin.prevout, undo);
+ txundo.vprevout.push_back(CTxInUndo());
+ ret = coins.Spend(txin.prevout, txundo.vprevout.back());
assert(ret);
- txundo.vprevout.push_back(undo);
}
}
@@ -1663,6 +1664,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size()));
std::vector<std::pair<uint256, CDiskTxPos> > vPos;
vPos.reserve(block.vtx.size());
+ blockundo.vtxundo.reserve(block.vtx.size() - 1);
for (unsigned int i = 0; i < block.vtx.size(); i++)
{
const CTransaction &tx = block.vtx[i];
@@ -1698,10 +1700,11 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
control.Add(vChecks);
}
- CTxUndo txundo;
- UpdateCoins(tx, state, view, txundo, pindex->nHeight);
- if (!tx.IsCoinBase())
- blockundo.vtxundo.push_back(txundo);
+ CTxUndo undoDummy;
+ if (i > 0) {
+ blockundo.vtxundo.push_back(CTxUndo());
+ }
+ UpdateCoins(tx, state, view, i == 0 ? undoDummy : blockundo.vtxundo.back(), pindex->nHeight);
vPos.push_back(std::make_pair(tx.GetHash(), pos));
pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION);