Pass a reference in SHAMap::compare

This commit is contained in:
Vinnie Falco
2015-07-07 12:22:50 -07:00
parent 73d64bbafc
commit 9eb0c2964c
3 changed files with 10 additions and 10 deletions

View File

@@ -1202,7 +1202,7 @@ void LedgerConsensusImp::createDisputes (
WriteLog (lsDEBUG, LedgerConsensus) << "createDisputes " WriteLog (lsDEBUG, LedgerConsensus) << "createDisputes "
<< m1->getHash() << " to " << m2->getHash(); << m1->getHash() << " to " << m2->getHash();
SHAMap::Delta differences; SHAMap::Delta differences;
m1->compare (m2, differences, 16384); m1->compare (*m2, differences, 16384);
int dc = 0; int dc = 0;
// for each difference between the transactions // for each difference between the transactions

View File

@@ -204,7 +204,7 @@ public:
// caution: otherMap must be accessed only by this function // caution: otherMap must be accessed only by this function
// return value: true=successfully completed, false=too different // return value: true=successfully completed, false=too different
bool compare (std::shared_ptr<SHAMap> const& otherMap, bool compare (SHAMap const& otherMap,
Delta& differences, int maxCount) const; Delta& differences, int maxCount) const;
int flushDirty (NodeObjectType t, std::uint32_t seq); int flushDirty (NodeObjectType t, std::uint32_t seq);

View File

@@ -113,7 +113,7 @@ bool SHAMap::walkBranch (SHAMapAbstractNode* node,
} }
bool bool
SHAMap::compare (std::shared_ptr<SHAMap> const& otherMap, SHAMap::compare (SHAMap const& otherMap,
Delta& differences, int maxCount) const Delta& differences, int maxCount) const
{ {
// compare two hash trees, add up to maxCount differences to the difference table // compare two hash trees, add up to maxCount differences to the difference table
@@ -121,15 +121,15 @@ SHAMap::compare (std::shared_ptr<SHAMap> const& otherMap,
// throws on corrupt tables or missing nodes // throws on corrupt tables or missing nodes
// CAUTION: otherMap is not locked and must be immutable // CAUTION: otherMap is not locked and must be immutable
assert (isValid () && otherMap && otherMap->isValid ()); assert (isValid () && otherMap.isValid ());
if (getHash () == otherMap->getHash ()) if (getHash () == otherMap.getHash ())
return true; return true;
using StackEntry = std::pair <SHAMapAbstractNode*, SHAMapAbstractNode*>; using StackEntry = std::pair <SHAMapAbstractNode*, SHAMapAbstractNode*>;
std::stack <StackEntry, std::vector<StackEntry>> nodeStack; // track nodes we've pushed std::stack <StackEntry, std::vector<StackEntry>> nodeStack; // track nodes we've pushed
nodeStack.push ({root_.get(), otherMap->root_.get()}); nodeStack.push ({root_.get(), otherMap.root_.get()});
while (!nodeStack.empty ()) while (!nodeStack.empty ())
{ {
SHAMapAbstractNode* ourNode = nodeStack.top().first; SHAMapAbstractNode* ourNode = nodeStack.top().first;
@@ -184,7 +184,7 @@ SHAMap::compare (std::shared_ptr<SHAMap> const& otherMap,
{ {
auto ours = static_cast<SHAMapTreeNode*>(ourNode); auto ours = static_cast<SHAMapTreeNode*>(ourNode);
auto other = static_cast<SHAMapInnerNode*>(otherNode); auto other = static_cast<SHAMapInnerNode*>(otherNode);
if (!otherMap->walkBranch (other, ours->peekItem (), if (!otherMap.walkBranch (other, ours->peekItem (),
false, differences, maxCount)) false, differences, maxCount))
return false; return false;
} }
@@ -208,15 +208,15 @@ SHAMap::compare (std::shared_ptr<SHAMap> const& otherMap,
{ {
// The other tree has a branch, we do not // The other tree has a branch, we do not
SHAMapAbstractNode* iNode = SHAMapAbstractNode* iNode =
otherMap->descendThrow(other, i); otherMap.descendThrow(other, i);
if (!otherMap->walkBranch (iNode, if (!otherMap.walkBranch (iNode,
std::shared_ptr<SHAMapItem const>(), std::shared_ptr<SHAMapItem const>(),
false, differences, maxCount)) false, differences, maxCount))
return false; return false;
} }
else // The two trees have different non-empty branches else // The two trees have different non-empty branches
nodeStack.push ({descendThrow (ours, i), nodeStack.push ({descendThrow (ours, i),
otherMap->descendThrow (other, i)}); otherMap.descendThrow (other, i)});
} }
} }
else else