aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@yanofsky.org>2016-11-21 11:47:12 -0500
committerSuhas Daftuar <sdaftuar@gmail.com>2017-05-04 16:50:52 -0400
commitc1235e3f2dd5b01b63b020d1b8f7283e8badaf09 (patch)
treee9ea1cd546eb391da083a0dadbabb4ccc82d0842 /src
parent71f1903353e6452fd4e80e8ae698a49d16a7b61d (diff)
Add RecursiveDynamicUsage overload for std::shared_ptr
This simplifies a few usage expressions.
Diffstat (limited to 'src')
-rw-r--r--src/core_memusage.h5
-rw-r--r--src/txmempool.cpp2
-rw-r--r--src/txmempool.h6
3 files changed, 9 insertions, 4 deletions
diff --git a/src/core_memusage.h b/src/core_memusage.h
index 5e10182075..e4ccd54c42 100644
--- a/src/core_memusage.h
+++ b/src/core_memusage.h
@@ -63,4 +63,9 @@ static inline size_t RecursiveDynamicUsage(const CBlockLocator& locator) {
return memusage::DynamicUsage(locator.vHave);
}
+template<typename X>
+static inline size_t RecursiveDynamicUsage(const std::shared_ptr<X>& p) {
+ return p ? memusage::DynamicUsage(p) + RecursiveDynamicUsage(*p) : 0;
+}
+
#endif // BITCOIN_CORE_MEMUSAGE_H
diff --git a/src/txmempool.cpp b/src/txmempool.cpp
index ac842da6bf..45980bb60e 100644
--- a/src/txmempool.cpp
+++ b/src/txmempool.cpp
@@ -23,7 +23,7 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFe
spendsCoinbase(_spendsCoinbase), sigOpCost(_sigOpsCost), lockPoints(lp)
{
nTxWeight = GetTransactionWeight(*tx);
- nUsageSize = RecursiveDynamicUsage(*tx) + memusage::DynamicUsage(tx);
+ nUsageSize = RecursiveDynamicUsage(tx);
nCountWithDescendants = 1;
nSizeWithDescendants = GetTxSize();
diff --git a/src/txmempool.h b/src/txmempool.h
index 4a83c3f844..ff90b4eda5 100644
--- a/src/txmempool.h
+++ b/src/txmempool.h
@@ -740,7 +740,7 @@ struct DisconnectedBlockTransactions {
void addTransaction(const CTransactionRef& tx)
{
queuedTx.insert(tx);
- cachedInnerUsage += RecursiveDynamicUsage(*tx) + memusage::DynamicUsage(tx);
+ cachedInnerUsage += RecursiveDynamicUsage(tx);
}
// Remove entries based on txid_index, and update memory usage.
@@ -753,7 +753,7 @@ struct DisconnectedBlockTransactions {
for (auto const &tx : vtx) {
auto it = queuedTx.find(tx->GetHash());
if (it != queuedTx.end()) {
- cachedInnerUsage -= RecursiveDynamicUsage(**it) + memusage::DynamicUsage(*it);
+ cachedInnerUsage -= RecursiveDynamicUsage(*it);
queuedTx.erase(it);
}
}
@@ -762,7 +762,7 @@ struct DisconnectedBlockTransactions {
// Remove an entry by insertion_order index, and update memory usage.
void removeEntry(indexed_disconnected_transactions::index<insertion_order>::type::iterator entry)
{
- cachedInnerUsage -= RecursiveDynamicUsage(**entry) + memusage::DynamicUsage(*entry);
+ cachedInnerUsage -= RecursiveDynamicUsage(*entry);
queuedTx.get<insertion_order>().erase(entry);
}