mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Cleanups. Remove extraneous reference count manipulations.
This commit is contained in:
@@ -140,9 +140,8 @@ public:
|
|||||||
boost::posix_time::ptime getCloseTime() const;
|
boost::posix_time::ptime getCloseTime() const;
|
||||||
|
|
||||||
// low level functions
|
// low level functions
|
||||||
SHAMap::pointer peekTransactionMap() { return mTransactionMap; }
|
SHAMap::ref peekTransactionMap() { return mTransactionMap; }
|
||||||
SHAMap::pointer peekAccountStateMap() { return mAccountStateMap; }
|
SHAMap::ref peekAccountStateMap() { return mAccountStateMap; }
|
||||||
Ledger::pointer snapShot(bool isMutable);
|
|
||||||
|
|
||||||
// ledger sync functions
|
// ledger sync functions
|
||||||
void setAcquiring(void);
|
void setAcquiring(void);
|
||||||
|
|||||||
20
src/SHAMap.h
20
src/SHAMap.h
@@ -23,10 +23,6 @@ class SHAMap;
|
|||||||
|
|
||||||
class SHAMapNode
|
class SHAMapNode
|
||||||
{ // Identifies a node in a SHA256 hash
|
{ // Identifies a node in a SHA256 hash
|
||||||
public:
|
|
||||||
typedef boost::shared_ptr<SHAMapNode> pointer;
|
|
||||||
typedef const boost::shared_ptr<SHAMapNode>& ref;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static uint256 smMasks[65]; // AND with hash to get node id
|
static uint256 smMasks[65]; // AND with hash to get node id
|
||||||
|
|
||||||
@@ -84,7 +80,8 @@ inline std::ostream& operator<<(std::ostream& out, const SHAMapNode& node) { ret
|
|||||||
class SHAMapItem
|
class SHAMapItem
|
||||||
{ // an item stored in a SHAMap
|
{ // an item stored in a SHAMap
|
||||||
public:
|
public:
|
||||||
typedef boost::shared_ptr<SHAMapItem> pointer;
|
typedef boost::shared_ptr<SHAMapItem> pointer;
|
||||||
|
typedef const boost::shared_ptr<SHAMapItem>& ref;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint256 mTag;
|
uint256 mTag;
|
||||||
@@ -136,7 +133,8 @@ class SHAMapTreeNode : public SHAMapNode
|
|||||||
friend class SHAMap;
|
friend class SHAMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef boost::shared_ptr<SHAMapTreeNode> pointer;
|
typedef boost::shared_ptr<SHAMapTreeNode> pointer;
|
||||||
|
typedef const boost::shared_ptr<SHAMapTreeNode>& ref;
|
||||||
|
|
||||||
enum TNType
|
enum TNType
|
||||||
{
|
{
|
||||||
@@ -163,7 +161,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
SHAMapTreeNode(uint32 seq, const SHAMapNode& nodeID); // empty node
|
SHAMapTreeNode(uint32 seq, const SHAMapNode& nodeID); // empty node
|
||||||
SHAMapTreeNode(const SHAMapTreeNode& node, uint32 seq); // copy node from older tree
|
SHAMapTreeNode(const SHAMapTreeNode& node, uint32 seq); // copy node from older tree
|
||||||
SHAMapTreeNode(const SHAMapNode& nodeID, const SHAMapItem::pointer& item, TNType type, uint32 seq);
|
SHAMapTreeNode(const SHAMapNode& nodeID, SHAMapItem::ref item, TNType type, uint32 seq);
|
||||||
|
|
||||||
// raw node functions
|
// raw node functions
|
||||||
SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned char>& data, uint32 seq, SHANodeFormat format);
|
SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned char>& data, uint32 seq, SHANodeFormat format);
|
||||||
@@ -200,7 +198,7 @@ public:
|
|||||||
|
|
||||||
// item node function
|
// item node function
|
||||||
bool hasItem() const { return !!mItem; }
|
bool hasItem() const { return !!mItem; }
|
||||||
SHAMapItem::pointer peekItem() { return mItem; }
|
SHAMapItem::ref peekItem() { return mItem; }
|
||||||
SHAMapItem::pointer getItem() const;
|
SHAMapItem::pointer getItem() const;
|
||||||
bool setItem(const SHAMapItem::pointer& i, TNType type);
|
bool setItem(const SHAMapItem::pointer& i, TNType type);
|
||||||
const uint256& getTag() const { return mItem->getTag(); }
|
const uint256& getTag() const { return mItem->getTag(); }
|
||||||
@@ -292,7 +290,7 @@ protected:
|
|||||||
SHAMapItem::pointer onlyBelow(SHAMapTreeNode*);
|
SHAMapItem::pointer onlyBelow(SHAMapTreeNode*);
|
||||||
void eraseChildren(SHAMapTreeNode::pointer);
|
void eraseChildren(SHAMapTreeNode::pointer);
|
||||||
|
|
||||||
bool walkBranch(SHAMapTreeNode* node, SHAMapItem::pointer otherMapItem, bool isFirstMap,
|
bool walkBranch(SHAMapTreeNode* node, SHAMapItem::ref otherMapItem, bool isFirstMap,
|
||||||
SHAMapDiff& differences, int& maxCount);
|
SHAMapDiff& differences, int& maxCount);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -321,8 +319,8 @@ public:
|
|||||||
uint256 getHash() { return root->getNodeHash(); }
|
uint256 getHash() { return root->getNodeHash(); }
|
||||||
|
|
||||||
// save a copy if you have a temporary anyway
|
// save a copy if you have a temporary anyway
|
||||||
bool updateGiveItem(const SHAMapItem::pointer&, bool isTransaction, bool hasMeta);
|
bool updateGiveItem(SHAMapItem::ref, bool isTransaction, bool hasMeta);
|
||||||
bool addGiveItem(const SHAMapItem::pointer&, bool isTransaction, bool hasMeta);
|
bool addGiveItem(SHAMapItem::ref, bool isTransaction, bool hasMeta);
|
||||||
|
|
||||||
// save a copy if you only need a temporary
|
// save a copy if you only need a temporary
|
||||||
SHAMapItem::pointer peekItem(const uint256& id);
|
SHAMapItem::pointer peekItem(const uint256& id);
|
||||||
|
|||||||
@@ -20,13 +20,15 @@ class SHAMapDiffNode
|
|||||||
mNodeID(id), mOurHash(ourHash), mOtherHash(otherHash) { ; }
|
mNodeID(id), mOurHash(ourHash), mOtherHash(otherHash) { ; }
|
||||||
};
|
};
|
||||||
|
|
||||||
bool SHAMap::walkBranch(SHAMapTreeNode* node, SHAMapItem::pointer otherMapItem, bool isFirstMap,
|
bool SHAMap::walkBranch(SHAMapTreeNode* node, SHAMapItem::ref otherMapItem, bool isFirstMap,
|
||||||
SHAMapDiff& differences, int& maxCount)
|
SHAMapDiff& differences, int& maxCount)
|
||||||
{
|
{
|
||||||
// Walk a branch of a SHAMap that's matched by an empty branch or single item in the other map
|
// Walk a branch of a SHAMap that's matched by an empty branch or single item in the other map
|
||||||
std::stack<SHAMapTreeNode*> nodeStack;
|
std::stack<SHAMapTreeNode*> nodeStack;
|
||||||
nodeStack.push(node);
|
nodeStack.push(node);
|
||||||
|
|
||||||
|
bool emptyBranch = !otherMapItem;
|
||||||
|
|
||||||
while (!nodeStack.empty())
|
while (!nodeStack.empty())
|
||||||
{
|
{
|
||||||
SHAMapTreeNode* node = nodeStack.top();
|
SHAMapTreeNode* node = nodeStack.top();
|
||||||
@@ -41,7 +43,7 @@ bool SHAMap::walkBranch(SHAMapTreeNode* node, SHAMapItem::pointer otherMapItem,
|
|||||||
{ // This is a leaf node, process its item
|
{ // This is a leaf node, process its item
|
||||||
SHAMapItem::pointer item = node->getItem();
|
SHAMapItem::pointer item = node->getItem();
|
||||||
|
|
||||||
if (otherMapItem && (otherMapItem->getTag() < item->getTag()))
|
if (!emptyBranch && (otherMapItem->getTag() < item->getTag()))
|
||||||
{ // this item comes after the item from the other map, so add the other item
|
{ // this item comes after the item from the other map, so add the other item
|
||||||
if (isFirstMap) // this is first map, so other item is from second
|
if (isFirstMap) // this is first map, so other item is from second
|
||||||
differences.insert(std::make_pair(otherMapItem->getTag(),
|
differences.insert(std::make_pair(otherMapItem->getTag(),
|
||||||
@@ -49,11 +51,12 @@ bool SHAMap::walkBranch(SHAMapTreeNode* node, SHAMapItem::pointer otherMapItem,
|
|||||||
else
|
else
|
||||||
differences.insert(std::make_pair(otherMapItem->getTag(),
|
differences.insert(std::make_pair(otherMapItem->getTag(),
|
||||||
std::make_pair(otherMapItem, SHAMapItem::pointer())));
|
std::make_pair(otherMapItem, SHAMapItem::pointer())));
|
||||||
if (--maxCount <= 0) return false;
|
if (--maxCount <= 0)
|
||||||
otherMapItem = SHAMapItem::pointer();
|
return false;
|
||||||
|
emptyBranch = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!otherMapItem) || (item->getTag() < otherMapItem->getTag()))
|
if (emptyBranch || (item->getTag() < otherMapItem->getTag()))
|
||||||
{ // unmatched
|
{ // unmatched
|
||||||
if (isFirstMap)
|
if (isFirstMap)
|
||||||
differences.insert(std::make_pair(item->getTag(), std::make_pair(item, SHAMapItem::pointer())));
|
differences.insert(std::make_pair(item->getTag(), std::make_pair(item, SHAMapItem::pointer())));
|
||||||
@@ -77,7 +80,7 @@ bool SHAMap::walkBranch(SHAMapTreeNode* node, SHAMapItem::pointer otherMapItem,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (otherMapItem)
|
if (!emptyBranch)
|
||||||
{ // otherMapItem was unmatched, must add
|
{ // otherMapItem was unmatched, must add
|
||||||
if (isFirstMap) // this is first map, so other item is from second
|
if (isFirstMap) // this is first map, so other item is from second
|
||||||
differences.insert(std::make_pair(otherMapItem->getTag(),
|
differences.insert(std::make_pair(otherMapItem->getTag(),
|
||||||
|
|||||||
Reference in New Issue
Block a user