Cleanups. Remove extraneous reference count manipulations.

This commit is contained in:
JoelKatz
2012-10-08 00:01:23 -07:00
parent 34a3124c11
commit 2d431cefd1
3 changed files with 21 additions and 21 deletions

View File

@@ -140,9 +140,8 @@ public:
boost::posix_time::ptime getCloseTime() const;
// low level functions
SHAMap::pointer peekTransactionMap() { return mTransactionMap; }
SHAMap::pointer peekAccountStateMap() { return mAccountStateMap; }
Ledger::pointer snapShot(bool isMutable);
SHAMap::ref peekTransactionMap() { return mTransactionMap; }
SHAMap::ref peekAccountStateMap() { return mAccountStateMap; }
// ledger sync functions
void setAcquiring(void);

View File

@@ -23,10 +23,6 @@ class SHAMap;
class SHAMapNode
{ // Identifies a node in a SHA256 hash
public:
typedef boost::shared_ptr<SHAMapNode> pointer;
typedef const boost::shared_ptr<SHAMapNode>& ref;
private:
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
{ // an item stored in a SHAMap
public:
typedef boost::shared_ptr<SHAMapItem> pointer;
typedef boost::shared_ptr<SHAMapItem> pointer;
typedef const boost::shared_ptr<SHAMapItem>& ref;
private:
uint256 mTag;
@@ -136,7 +133,8 @@ class SHAMapTreeNode : public SHAMapNode
friend class SHAMap;
public:
typedef boost::shared_ptr<SHAMapTreeNode> pointer;
typedef boost::shared_ptr<SHAMapTreeNode> pointer;
typedef const boost::shared_ptr<SHAMapTreeNode>& ref;
enum TNType
{
@@ -163,7 +161,7 @@ private:
public:
SHAMapTreeNode(uint32 seq, const SHAMapNode& nodeID); // empty node
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
SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned char>& data, uint32 seq, SHANodeFormat format);
@@ -200,7 +198,7 @@ public:
// item node function
bool hasItem() const { return !!mItem; }
SHAMapItem::pointer peekItem() { return mItem; }
SHAMapItem::ref peekItem() { return mItem; }
SHAMapItem::pointer getItem() const;
bool setItem(const SHAMapItem::pointer& i, TNType type);
const uint256& getTag() const { return mItem->getTag(); }
@@ -292,7 +290,7 @@ protected:
SHAMapItem::pointer onlyBelow(SHAMapTreeNode*);
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);
public:
@@ -321,8 +319,8 @@ public:
uint256 getHash() { return root->getNodeHash(); }
// save a copy if you have a temporary anyway
bool updateGiveItem(const SHAMapItem::pointer&, bool isTransaction, bool hasMeta);
bool addGiveItem(const SHAMapItem::pointer&, bool isTransaction, bool hasMeta);
bool updateGiveItem(SHAMapItem::ref, bool isTransaction, bool hasMeta);
bool addGiveItem(SHAMapItem::ref, bool isTransaction, bool hasMeta);
// save a copy if you only need a temporary
SHAMapItem::pointer peekItem(const uint256& id);

View File

@@ -20,13 +20,15 @@ class SHAMapDiffNode
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)
{
// Walk a branch of a SHAMap that's matched by an empty branch or single item in the other map
std::stack<SHAMapTreeNode*> nodeStack;
nodeStack.push(node);
bool emptyBranch = !otherMapItem;
while (!nodeStack.empty())
{
SHAMapTreeNode* node = nodeStack.top();
@@ -41,7 +43,7 @@ bool SHAMap::walkBranch(SHAMapTreeNode* node, SHAMapItem::pointer otherMapItem,
{ // This is a leaf node, process its item
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
if (isFirstMap) // this is first map, so other item is from second
differences.insert(std::make_pair(otherMapItem->getTag(),
@@ -49,11 +51,12 @@ bool SHAMap::walkBranch(SHAMapTreeNode* node, SHAMapItem::pointer otherMapItem,
else
differences.insert(std::make_pair(otherMapItem->getTag(),
std::make_pair(otherMapItem, SHAMapItem::pointer())));
if (--maxCount <= 0) return false;
otherMapItem = SHAMapItem::pointer();
if (--maxCount <= 0)
return false;
emptyBranch = true;
}
if ((!otherMapItem) || (item->getTag() < otherMapItem->getTag()))
if (emptyBranch || (item->getTag() < otherMapItem->getTag()))
{ // unmatched
if (isFirstMap)
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
if (isFirstMap) // this is first map, so other item is from second
differences.insert(std::make_pair(otherMapItem->getTag(),