mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Improvements because items in SHAMaps are immutable:
* SHAMapItem::getData is not needed * SHAMapTreeNode::getItem is not needed * SHAMapTreeNode::getData is not needed * No need to copy them when constructing transactions * No need to copy them when computing map deltas * No need to copy them in deepCompare * No need to copy them in SHAMapTreeNode's copy constructor
This commit is contained in:
@@ -392,7 +392,7 @@ Transaction::pointer Ledger::getTransaction (uint256 const& transID) const
|
||||
return txn;
|
||||
|
||||
if (type == SHAMapTreeNode::tnTRANSACTION_NM)
|
||||
txn = Transaction::sharedTransaction (item->getData (), true);
|
||||
txn = Transaction::sharedTransaction (item->peekData (), true);
|
||||
else if (type == SHAMapTreeNode::tnTRANSACTION_MD)
|
||||
{
|
||||
Blob txnData;
|
||||
|
||||
@@ -54,6 +54,7 @@ public:
|
||||
typedef const boost::shared_ptr<SHAMap>& ref;
|
||||
|
||||
typedef std::pair<SHAMapItem::pointer, SHAMapItem::pointer> DeltaItem;
|
||||
typedef std::pair<SHAMapItem::ref, SHAMapItem::ref> DeltaRef;
|
||||
typedef std::map<uint256, DeltaItem> Delta;
|
||||
typedef boost::unordered_map<SHAMapNode, SHAMapTreeNode::pointer> NodeMap;
|
||||
|
||||
|
||||
@@ -62,17 +62,17 @@ bool SHAMap::walkBranch (SHAMapTreeNode* node, SHAMapItem::ref otherMapItem, boo
|
||||
else
|
||||
{
|
||||
// This is a leaf node, process its item
|
||||
SHAMapItem::pointer item = node->getItem ();
|
||||
SHAMapItem::pointer item = node->peekItem ();
|
||||
|
||||
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 (),
|
||||
std::make_pair (SHAMapItem::pointer (), otherMapItem)));
|
||||
DeltaRef (SHAMapItem::pointer (), otherMapItem)));
|
||||
else
|
||||
differences.insert (std::make_pair (otherMapItem->getTag (),
|
||||
std::make_pair (otherMapItem, SHAMapItem::pointer ())));
|
||||
DeltaRef (otherMapItem, SHAMapItem::pointer ())));
|
||||
|
||||
if (--maxCount <= 0)
|
||||
return false;
|
||||
@@ -84,9 +84,9 @@ bool SHAMap::walkBranch (SHAMapTreeNode* node, SHAMapItem::ref otherMapItem, boo
|
||||
{
|
||||
// unmatched
|
||||
if (isFirstMap)
|
||||
differences.insert (std::make_pair (item->getTag (), std::make_pair (item, SHAMapItem::pointer ())));
|
||||
differences.insert (std::make_pair (item->getTag (), DeltaRef (item, SHAMapItem::pointer ())));
|
||||
else
|
||||
differences.insert (std::make_pair (item->getTag (), std::make_pair (SHAMapItem::pointer (), item)));
|
||||
differences.insert (std::make_pair (item->getTag (), DeltaRef (SHAMapItem::pointer (), item)));
|
||||
|
||||
if (--maxCount <= 0)
|
||||
return false;
|
||||
@@ -97,9 +97,9 @@ bool SHAMap::walkBranch (SHAMapTreeNode* node, SHAMapItem::ref otherMapItem, boo
|
||||
{
|
||||
// non-matching items
|
||||
if (isFirstMap)
|
||||
differences.insert (std::make_pair (otherMapItem->getTag (), std::make_pair (item, otherMapItem)));
|
||||
differences.insert (std::make_pair (otherMapItem->getTag (), DeltaRef (item, otherMapItem)));
|
||||
else
|
||||
differences.insert (std::make_pair (otherMapItem->getTag (), std::make_pair (otherMapItem, item)));
|
||||
differences.insert (std::make_pair (otherMapItem->getTag (), DeltaRef (otherMapItem, item)));
|
||||
|
||||
if (--maxCount <= 0)
|
||||
return false;
|
||||
@@ -115,10 +115,10 @@ bool SHAMap::walkBranch (SHAMapTreeNode* node, SHAMapItem::ref otherMapItem, boo
|
||||
// otherMapItem was unmatched, must add
|
||||
if (isFirstMap) // this is first map, so other item is from second
|
||||
differences.insert (std::make_pair (otherMapItem->getTag (),
|
||||
std::make_pair (SHAMapItem::pointer (), otherMapItem)));
|
||||
DeltaRef (SHAMapItem::pointer (), otherMapItem)));
|
||||
else
|
||||
differences.insert (std::make_pair (otherMapItem->getTag (),
|
||||
std::make_pair (otherMapItem, SHAMapItem::pointer ())));
|
||||
DeltaRef (otherMapItem, SHAMapItem::pointer ())));
|
||||
|
||||
if (--maxCount <= 0)
|
||||
return false;
|
||||
@@ -167,7 +167,7 @@ bool SHAMap::compare (SHAMap::ref otherMap, Delta& differences, int maxCount)
|
||||
if (ourNode->peekData () != otherNode->peekData ())
|
||||
{
|
||||
differences.insert (std::make_pair (ourNode->getTag (),
|
||||
std::make_pair (ourNode->getItem (), otherNode->getItem ())));
|
||||
DeltaRef (ourNode->peekItem (), otherNode->peekItem ())));
|
||||
|
||||
if (--maxCount <= 0)
|
||||
return false;
|
||||
@@ -176,13 +176,13 @@ bool SHAMap::compare (SHAMap::ref otherMap, Delta& differences, int maxCount)
|
||||
else
|
||||
{
|
||||
differences.insert (std::make_pair (ourNode->getTag (),
|
||||
std::make_pair (ourNode->getItem (), SHAMapItem::pointer ())));
|
||||
DeltaRef (ourNode->peekItem (), SHAMapItem::pointer ())));
|
||||
|
||||
if (--maxCount <= 0)
|
||||
return false;
|
||||
|
||||
differences.insert (std::make_pair (otherNode->getTag (),
|
||||
std::make_pair (SHAMapItem::pointer (), otherNode->getItem ())));
|
||||
DeltaRef (SHAMapItem::pointer (), otherNode->peekItem ())));
|
||||
|
||||
if (--maxCount <= 0)
|
||||
return false;
|
||||
@@ -190,12 +190,12 @@ bool SHAMap::compare (SHAMap::ref otherMap, Delta& differences, int maxCount)
|
||||
}
|
||||
else if (ourNode->isInner () && otherNode->isLeaf ())
|
||||
{
|
||||
if (!walkBranch (ourNode, otherNode->getItem (), true, differences, maxCount))
|
||||
if (!walkBranch (ourNode, otherNode->peekItem (), true, differences, maxCount))
|
||||
return false;
|
||||
}
|
||||
else if (ourNode->isLeaf () && otherNode->isInner ())
|
||||
{
|
||||
if (!otherMap->walkBranch (otherNode, ourNode->getItem (), false, differences, maxCount))
|
||||
if (!otherMap->walkBranch (otherNode, ourNode->peekItem (), false, differences, maxCount))
|
||||
return false;
|
||||
}
|
||||
else if (ourNode->isInner () && otherNode->isInner ())
|
||||
|
||||
@@ -43,10 +43,6 @@ public:
|
||||
{
|
||||
return mTag;
|
||||
}
|
||||
Blob getData () const
|
||||
{
|
||||
return mData.getData ();
|
||||
}
|
||||
Blob const& peekData () const
|
||||
{
|
||||
return mData.peekData ();
|
||||
|
||||
@@ -439,7 +439,7 @@ bool SHAMap::deepCompare (SHAMap& other)
|
||||
|
||||
if (node->peekItem ()->getTag () != otherNode->peekItem ()->getTag ()) return false;
|
||||
|
||||
if (node->peekItem ()->getData () != otherNode->peekItem ()->getData ()) return false;
|
||||
if (node->peekItem ()->peekData () != otherNode->peekItem ()->peekData ()) return false;
|
||||
}
|
||||
else if (node->isInner ())
|
||||
{
|
||||
|
||||
@@ -32,12 +32,7 @@ SHAMapTreeNode::SHAMapTreeNode (const SHAMapTreeNode& node, uint32 seq) : SHAMap
|
||||
mHash (node.mHash), mSeq (seq), mType (node.mType), mIsBranch (node.mIsBranch), mFullBelow (false)
|
||||
{
|
||||
if (node.mItem)
|
||||
{
|
||||
if ((mSeq == 0) && (node.mSeq == 0))
|
||||
mItem = node.mItem; // two immutable nodes can share an item
|
||||
else
|
||||
mItem = boost::make_shared<SHAMapItem> (*node.mItem);
|
||||
}
|
||||
mItem = node.mItem;
|
||||
else
|
||||
memcpy (mHashes, node.mHashes, sizeof (mHashes));
|
||||
}
|
||||
@@ -387,12 +382,6 @@ bool SHAMapTreeNode::setItem (SHAMapItem::ref i, TNType type)
|
||||
return updateHash ();
|
||||
}
|
||||
|
||||
SHAMapItem::pointer SHAMapTreeNode::getItem () const
|
||||
{
|
||||
assert (isLeaf ());
|
||||
return boost::make_shared<SHAMapItem> (*mItem);
|
||||
}
|
||||
|
||||
bool SHAMapTreeNode::isEmpty () const
|
||||
{
|
||||
return mIsBranch == 0;
|
||||
|
||||
@@ -141,7 +141,6 @@ public:
|
||||
{ // CAUTION: Do not modify the item
|
||||
return mItem;
|
||||
}
|
||||
SHAMapItem::pointer getItem () const;
|
||||
bool setItem (SHAMapItem::ref i, TNType type);
|
||||
uint256 const& getTag () const
|
||||
{
|
||||
@@ -151,10 +150,6 @@ public:
|
||||
{
|
||||
return mItem->peekData ();
|
||||
}
|
||||
Blob getData () const
|
||||
{
|
||||
return mItem->getData ();
|
||||
}
|
||||
|
||||
// sync functions
|
||||
bool isFullBelow (void) const
|
||||
|
||||
@@ -294,7 +294,7 @@ bool Transaction::convertToTransactions (uint32 firstLedgerSeq, uint32 secondLed
|
||||
if (!!first)
|
||||
{
|
||||
// transaction in our table
|
||||
firstTrans = sharedTransaction (first->getData (), checkFirstTransactions);
|
||||
firstTrans = sharedTransaction (first->peekData (), checkFirstTransactions);
|
||||
|
||||
if ((firstTrans->getStatus () == INVALID) || (firstTrans->getID () != id ))
|
||||
{
|
||||
@@ -307,7 +307,7 @@ bool Transaction::convertToTransactions (uint32 firstLedgerSeq, uint32 secondLed
|
||||
if (!!second)
|
||||
{
|
||||
// transaction in other table
|
||||
secondTrans = sharedTransaction (second->getData (), checkSecondTransactions);
|
||||
secondTrans = sharedTransaction (second->peekData (), checkSecondTransactions);
|
||||
|
||||
if ((secondTrans->getStatus () == INVALID) || (secondTrans->getID () != id))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user