aboutsummaryrefslogtreecommitdiff
path: root/src/main.h
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2013-01-20 18:05:34 +0100
committerPieter Wuille <pieter.wuille@gmail.com>2013-01-26 18:46:12 +0100
commitf369d02c51077ffa1644954d0478e93966e1bb72 (patch)
tree2d4d583878dae9762388a890a8d64d355d09ceef /src/main.h
parent71eccdeafff03a1c68c93b223427141f0885efc6 (diff)
Various performance tweaks to CCoinsView
* Pass txid's to CCoinsView functions by reference instead of by value * Add a method to swap CCoins, and use it in some places to avoid a allocating copy + destruct. * Optimize CCoinsViewCache::FetchCoins to do only a single search through the backing map.
Diffstat (limited to 'src/main.h')
-rw-r--r--src/main.h35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/main.h b/src/main.h
index edfea7b510..d5f7093e42 100644
--- a/src/main.h
+++ b/src/main.h
@@ -918,6 +918,15 @@ public:
void Cleanup() {
while (vout.size() > 0 && vout.back().IsNull())
vout.pop_back();
+ if (vout.empty())
+ std::vector<CTxOut>().swap(vout);
+ }
+
+ void swap(CCoins &to) {
+ std::swap(to.fCoinBase, fCoinBase);
+ to.vout.swap(vout);
+ std::swap(to.nHeight, nHeight);
+ std::swap(to.nVersion, nVersion);
}
// equality test
@@ -2077,14 +2086,14 @@ class CCoinsView
{
public:
// Retrieve the CCoins (unspent transaction outputs) for a given txid
- virtual bool GetCoins(uint256 txid, CCoins &coins);
+ virtual bool GetCoins(const uint256 &txid, CCoins &coins);
// Modify the CCoins for a given txid
- virtual bool SetCoins(uint256 txid, const CCoins &coins);
+ virtual bool SetCoins(const uint256 &txid, const CCoins &coins);
// Just check whether we have data for a given txid.
// This may (but cannot always) return true for fully spent transactions
- virtual bool HaveCoins(uint256 txid);
+ virtual bool HaveCoins(const uint256 &txid);
// Retrieve the block index whose state this CCoinsView currently represents
virtual CBlockIndex *GetBestBlock();
@@ -2110,9 +2119,9 @@ protected:
public:
CCoinsViewBacked(CCoinsView &viewIn);
- bool GetCoins(uint256 txid, CCoins &coins);
- bool SetCoins(uint256 txid, const CCoins &coins);
- bool HaveCoins(uint256 txid);
+ bool GetCoins(const uint256 &txid, CCoins &coins);
+ bool SetCoins(const uint256 &txid, const CCoins &coins);
+ bool HaveCoins(const uint256 &txid);
CBlockIndex *GetBestBlock();
bool SetBestBlock(CBlockIndex *pindex);
void SetBackend(CCoinsView &viewIn);
@@ -2131,9 +2140,9 @@ public:
CCoinsViewCache(CCoinsView &baseIn, bool fDummy = false);
// Standard CCoinsView methods
- bool GetCoins(uint256 txid, CCoins &coins);
- bool SetCoins(uint256 txid, const CCoins &coins);
- bool HaveCoins(uint256 txid);
+ bool GetCoins(const uint256 &txid, CCoins &coins);
+ bool SetCoins(const uint256 &txid, const CCoins &coins);
+ bool HaveCoins(const uint256 &txid);
CBlockIndex *GetBestBlock();
bool SetBestBlock(CBlockIndex *pindex);
bool BatchWrite(const std::map<uint256, CCoins> &mapCoins, CBlockIndex *pindex);
@@ -2141,7 +2150,7 @@ public:
// Return a modifiable reference to a CCoins. Check HaveCoins first.
// Many methods explicitly require a CCoinsViewCache because of this method, to reduce
// copying.
- CCoins &GetCoins(uint256 txid);
+ CCoins &GetCoins(const uint256 &txid);
// Push the modifications applied to this cache to its base.
// Failure to call this method before destruction will cause the changes to be forgotten.
@@ -2151,7 +2160,7 @@ public:
unsigned int GetCacheSize();
private:
- std::map<uint256,CCoins>::iterator FetchCoins(uint256 txid);
+ std::map<uint256,CCoins>::iterator FetchCoins(const uint256 &txid);
};
/** CCoinsView that brings transactions from a memorypool into view.
@@ -2163,8 +2172,8 @@ protected:
public:
CCoinsViewMemPool(CCoinsView &baseIn, CTxMemPool &mempoolIn);
- bool GetCoins(uint256 txid, CCoins &coins);
- bool HaveCoins(uint256 txid);
+ bool GetCoins(const uint256 &txid, CCoins &coins);
+ bool HaveCoins(const uint256 &txid);
};
/** Global variable that points to the active CCoinsView (protected by cs_main) */