mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Avoid some extraneous reference count operations.
This commit is contained in:
@@ -139,16 +139,18 @@ void SHAMap::dirtyUp(std::stack<SHAMapTreeNode::pointer>& stack, const uint256&
|
||||
}
|
||||
}
|
||||
|
||||
SHAMapTreeNode::pointer SHAMap::checkCacheNode(const SHAMapNode& iNode)
|
||||
static const SHAMapTreeNode::pointer no_node;
|
||||
|
||||
SHAMapTreeNode::ref SHAMap::checkCacheNode(const SHAMapNode& iNode)
|
||||
{
|
||||
boost::unordered_map<SHAMapNode, SHAMapTreeNode::pointer>::iterator it = mTNByID.find(iNode);
|
||||
if (it == mTNByID.end())
|
||||
return SHAMapTreeNode::pointer();
|
||||
return no_node;
|
||||
it->second->touch(mSeq);
|
||||
return it->second;
|
||||
}
|
||||
|
||||
SHAMapTreeNode::pointer SHAMap::walkTo(const uint256& id, bool modify)
|
||||
SHAMapTreeNode::ref SHAMap::walkTo(const uint256& id, bool modify)
|
||||
{ // walk down to the terminal node for this ID
|
||||
|
||||
SHAMapTreeNode::pointer inNode = root;
|
||||
@@ -370,42 +372,44 @@ void SHAMap::eraseChildren(SHAMapTreeNode::pointer node)
|
||||
return;
|
||||
}
|
||||
|
||||
SHAMapItem::pointer SHAMap::peekFirstItem()
|
||||
static const SHAMapItem::pointer no_item;
|
||||
|
||||
SHAMapItem::ref SHAMap::peekFirstItem()
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
SHAMapTreeNode *node = firstBelow(root.get());
|
||||
if (!node)
|
||||
return SHAMapItem::pointer();
|
||||
return no_item;
|
||||
return node->peekItem();
|
||||
}
|
||||
|
||||
SHAMapItem::pointer SHAMap::peekFirstItem(SHAMapTreeNode::TNType& type)
|
||||
SHAMapItem::ref SHAMap::peekFirstItem(SHAMapTreeNode::TNType& type)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
SHAMapTreeNode *node = firstBelow(root.get());
|
||||
if (!node)
|
||||
return SHAMapItem::pointer();
|
||||
return no_item;
|
||||
type = node->getType();
|
||||
return node->peekItem();
|
||||
}
|
||||
|
||||
SHAMapItem::pointer SHAMap::peekLastItem()
|
||||
SHAMapItem::ref SHAMap::peekLastItem()
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
SHAMapTreeNode *node = lastBelow(root.get());
|
||||
if (!node)
|
||||
return SHAMapItem::pointer();
|
||||
return no_item;
|
||||
return node->peekItem();
|
||||
}
|
||||
|
||||
SHAMapItem::pointer SHAMap::peekNextItem(const uint256& id)
|
||||
SHAMapItem::ref SHAMap::peekNextItem(const uint256& id)
|
||||
{
|
||||
SHAMapTreeNode::TNType type;
|
||||
return peekNextItem(id, type);
|
||||
}
|
||||
|
||||
|
||||
SHAMapItem::pointer SHAMap::peekNextItem(const uint256& id, SHAMapTreeNode::TNType& type)
|
||||
SHAMapItem::ref SHAMap::peekNextItem(const uint256& id, SHAMapTreeNode::TNType& type)
|
||||
{ // Get a pointer to the next item in the tree after a given item - item must be in tree
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
|
||||
@@ -438,10 +442,10 @@ SHAMapItem::pointer SHAMap::peekNextItem(const uint256& id, SHAMapTreeNode::TNTy
|
||||
}
|
||||
}
|
||||
// must be last item
|
||||
return SHAMapItem::pointer();
|
||||
return no_item;
|
||||
}
|
||||
|
||||
SHAMapItem::pointer SHAMap::peekPrevItem(const uint256& id)
|
||||
SHAMapItem::ref SHAMap::peekPrevItem(const uint256& id)
|
||||
{ // Get a pointer to the previous item in the tree after a given item - item must be in tree
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
|
||||
@@ -467,24 +471,24 @@ SHAMapItem::pointer SHAMap::peekPrevItem(const uint256& id)
|
||||
}
|
||||
}
|
||||
// must be last item
|
||||
return SHAMapItem::pointer();
|
||||
return no_item;
|
||||
}
|
||||
|
||||
SHAMapItem::pointer SHAMap::peekItem(const uint256& id)
|
||||
SHAMapItem::ref SHAMap::peekItem(const uint256& id)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
SHAMapTreeNode* leaf = walkToPointer(id);
|
||||
if (!leaf)
|
||||
return SHAMapItem::pointer();
|
||||
return no_item;
|
||||
return leaf->peekItem();
|
||||
}
|
||||
|
||||
SHAMapItem::pointer SHAMap::peekItem(const uint256& id, SHAMapTreeNode::TNType& type)
|
||||
SHAMapItem::ref SHAMap::peekItem(const uint256& id, SHAMapTreeNode::TNType& type)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
SHAMapTreeNode* leaf = walkToPointer(id);
|
||||
if (!leaf)
|
||||
return SHAMapItem::pointer();
|
||||
return no_item;
|
||||
type = leaf->getType();
|
||||
return leaf->peekItem();
|
||||
}
|
||||
|
||||
@@ -347,9 +347,9 @@ protected:
|
||||
|
||||
void dirtyUp(std::stack<SHAMapTreeNode::pointer>& stack, const uint256& target, uint256 prevHash);
|
||||
std::stack<SHAMapTreeNode::pointer> getStack(const uint256& id, bool include_nonmatching_leaf, bool partialOk);
|
||||
SHAMapTreeNode::pointer walkTo(const uint256& id, bool modify);
|
||||
SHAMapTreeNode::ref walkTo(const uint256& id, bool modify);
|
||||
SHAMapTreeNode* walkToPointer(const uint256& id);
|
||||
SHAMapTreeNode::pointer checkCacheNode(const SHAMapNode&);
|
||||
SHAMapTreeNode::ref checkCacheNode(const SHAMapNode&);
|
||||
void returnNode(SHAMapTreeNode::pointer&, bool modify);
|
||||
void trackNewNode(SHAMapTreeNode::pointer&);
|
||||
|
||||
@@ -396,16 +396,16 @@ public:
|
||||
bool addGiveItem(SHAMapItem::ref, bool isTransaction, bool hasMeta);
|
||||
|
||||
// save a copy if you only need a temporary
|
||||
SHAMapItem::pointer peekItem(const uint256& id);
|
||||
SHAMapItem::pointer peekItem(const uint256& id, SHAMapTreeNode::TNType& type);
|
||||
SHAMapItem::ref peekItem(const uint256& id);
|
||||
SHAMapItem::ref peekItem(const uint256& id, SHAMapTreeNode::TNType& type);
|
||||
|
||||
// traverse functions
|
||||
SHAMapItem::pointer peekFirstItem();
|
||||
SHAMapItem::pointer peekFirstItem(SHAMapTreeNode::TNType& type);
|
||||
SHAMapItem::pointer peekLastItem();
|
||||
SHAMapItem::pointer peekNextItem(const uint256&);
|
||||
SHAMapItem::pointer peekNextItem(const uint256&, SHAMapTreeNode::TNType& type);
|
||||
SHAMapItem::pointer peekPrevItem(const uint256&);
|
||||
SHAMapItem::ref peekFirstItem();
|
||||
SHAMapItem::ref peekFirstItem(SHAMapTreeNode::TNType& type);
|
||||
SHAMapItem::ref peekLastItem();
|
||||
SHAMapItem::ref peekNextItem(const uint256&);
|
||||
SHAMapItem::ref peekNextItem(const uint256&, SHAMapTreeNode::TNType& type);
|
||||
SHAMapItem::ref peekPrevItem(const uint256&);
|
||||
|
||||
// comparison/sync functions
|
||||
void getMissingNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<uint256>& hashes, int max,
|
||||
|
||||
Reference in New Issue
Block a user