diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2017-04-25 11:29:27 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2017-06-01 11:56:06 -0700 |
commit | bd83111a0fcfdb97204a0180bcf861d3b53bb6c2 (patch) | |
tree | 365ac791ba05350f8b28f06076157e0d9edacae6 /src | |
parent | cb2c7fdac2dc74368ed24ae4717ed72178956b92 (diff) |
Optimization: Coin&& to ApplyTxInUndo
This avoids a prevector copy in ApplyTxInUndo.
Diffstat (limited to 'src')
-rw-r--r-- | src/test/coins_tests.cpp | 6 | ||||
-rw-r--r-- | src/validation.cpp | 10 |
2 files changed, 8 insertions, 8 deletions
diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index e86c719944..9c758ee9ab 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -17,7 +17,7 @@ #include <boost/test/unit_test.hpp> -int ApplyTxInUndo(const Coin& undo, CCoinsViewCache& view, const COutPoint& out); +int ApplyTxInUndo(Coin&& undo, CCoinsViewCache& view, const COutPoint& out); void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, CTxUndo &txundo, int nHeight); namespace @@ -371,8 +371,8 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test) // restore inputs if (!tx.IsCoinBase()) { const COutPoint &out = tx.vin[0].prevout; - const Coin &undoin = undo.vprevout[0]; - ApplyTxInUndo(undoin, *(stack.back()), out); + Coin coin = undo.vprevout[0]; + ApplyTxInUndo(std::move(coin), *(stack.back()), out); } // Store as a candidate for reconnection disconnectedids.insert(undohash); diff --git a/src/validation.cpp b/src/validation.cpp index dad0e1a3ee..d6cc59b487 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1256,7 +1256,7 @@ enum DisconnectResult * @param out The out point that corresponds to the tx input. * @return A DisconnectResult as an int */ -int ApplyTxInUndo(const Coin& undo, CCoinsViewCache& view, const COutPoint& out) +int ApplyTxInUndo(Coin&& undo, CCoinsViewCache& view, const COutPoint& out) { bool fClean = true; @@ -1277,7 +1277,7 @@ int ApplyTxInUndo(const Coin& undo, CCoinsViewCache& view, const COutPoint& out) if (coins->IsAvailable(out.n)) fClean = false; // overwriting existing output if (coins->vout.size() < out.n+1) coins->vout.resize(out.n+1); - coins->vout[out.n] = undo.out; + coins->vout[out.n] = std::move(undo.out); return fClean ? DISCONNECT_OK : DISCONNECT_UNCLEAN; } @@ -1326,18 +1326,18 @@ static DisconnectResult DisconnectBlock(const CBlock& block, const CBlockIndex* // restore inputs if (i > 0) { // not coinbases - const CTxUndo &txundo = blockUndo.vtxundo[i-1]; + CTxUndo &txundo = blockUndo.vtxundo[i-1]; if (txundo.vprevout.size() != tx.vin.size()) { error("DisconnectBlock(): transaction and undo data inconsistent"); return DISCONNECT_FAILED; } for (unsigned int j = tx.vin.size(); j-- > 0;) { const COutPoint &out = tx.vin[j].prevout; - const Coin &undo = txundo.vprevout[j]; - int res = ApplyTxInUndo(undo, view, out); + int res = ApplyTxInUndo(std::move(txundo.vprevout[j]), view, out); if (res == DISCONNECT_FAILED) return DISCONNECT_FAILED; fClean = fClean && res != DISCONNECT_UNCLEAN; } + // At this point, all of txundo.vprevout should have been moved out. } } |