Skip to content

Commit 37a90f1

Browse files
ryanofskysdaftuar
authored andcommitted
Add RecursiveDynamicUsage overload for std::shared_ptr
This simplifies a few usage expressions.
1 parent 8687c74 commit 37a90f1

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/core_memusage.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,9 @@ static inline size_t RecursiveDynamicUsage(const CBlockLocator& locator) {
6363
return memusage::DynamicUsage(locator.vHave);
6464
}
6565

66+
template<typename X>
67+
static inline size_t RecursiveDynamicUsage(const std::shared_ptr<X>& p) {
68+
return RecursiveDynamicUsage(*p) + memusage::DynamicUsage(p);
69+
}
70+
6671
#endif // BITCOIN_CORE_MEMUSAGE_H

src/txmempool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFe
3030
{
3131
nTxWeight = GetTransactionWeight(*tx);
3232
nModSize = tx->CalculateModifiedSize(GetTxSize());
33-
nUsageSize = RecursiveDynamicUsage(*tx) + memusage::DynamicUsage(tx);
33+
nUsageSize = RecursiveDynamicUsage(tx);
3434

3535
nCountWithDescendants = 1;
3636
nSizeWithDescendants = GetTxSize();

src/txmempool.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ struct DisconnectedBlockTransactions {
773773
void addTransaction(CTransactionRef tx)
774774
{
775775
queuedTx.insert(tx);
776-
cachedInnerUsage += RecursiveDynamicUsage(*tx) + memusage::DynamicUsage(tx);
776+
cachedInnerUsage += RecursiveDynamicUsage(tx);
777777
}
778778

779779
// Remove entries based on txid_index, and update memory usage.
@@ -782,7 +782,7 @@ struct DisconnectedBlockTransactions {
782782
for (auto const &tx : vtx) {
783783
auto it = queuedTx.find(tx->GetHash());
784784
if (it != queuedTx.end()) {
785-
cachedInnerUsage -= RecursiveDynamicUsage(**it) + memusage::DynamicUsage(*it);
785+
cachedInnerUsage -= RecursiveDynamicUsage(*it);
786786
queuedTx.erase(it);
787787
}
788788
}
@@ -791,7 +791,7 @@ struct DisconnectedBlockTransactions {
791791
// Remove an entry by insertion_order index, and update memory usage.
792792
void removeEntry(indexed_disconnected_transactions::index<insertion_order>::type::iterator entry)
793793
{
794-
cachedInnerUsage -= RecursiveDynamicUsage(**entry) + memusage::DynamicUsage(*entry);
794+
cachedInnerUsage -= RecursiveDynamicUsage(*entry);
795795
queuedTx.get<insertion_order>().erase(entry);
796796
}
797797

0 commit comments

Comments
 (0)