Add method to remove a tx from CCoinsViewCache if it is unchanged

This commit is contained in:
Matt Corallo 2015-10-21 17:41:40 -07:00
parent 4077ad20d0
commit 74d0f90262
2 changed files with 15 additions and 0 deletions

View file

@ -206,6 +206,15 @@ bool CCoinsViewCache::Flush() {
return fOk; return fOk;
} }
void CCoinsViewCache::Uncache(const uint256& hash)
{
CCoinsMap::iterator it = cacheCoins.find(hash);
if (it != cacheCoins.end() && it->second.flags == 0) {
cachedCoinsUsage -= it->second.coins.DynamicMemoryUsage();
cacheCoins.erase(it);
}
}
unsigned int CCoinsViewCache::GetCacheSize() const { unsigned int CCoinsViewCache::GetCacheSize() const {
return cacheCoins.size(); return cacheCoins.size();
} }

View file

@ -437,6 +437,12 @@ public:
*/ */
bool Flush(); bool Flush();
/**
* Removes the transaction with the given hash from the cache, if it is
* not modified.
*/
void Uncache(const uint256 &txid);
//! Calculate the size of the cache (in number of transactions) //! Calculate the size of the cache (in number of transactions)
unsigned int GetCacheSize() const; unsigned int GetCacheSize() const;