From 0b7dc95d95ca98bab8ebcdfd1f990991f3165f3f Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 4 Sep 2014 10:19:51 -0700 Subject: [PATCH] [FOLD] Fixes: * Fix build error on clang * Fix issue Nik caught * Take suggestions from code review --- src/ripple/module/app/shamap/SHAMap.cpp | 29 +++++++++---------- src/ripple/module/app/shamap/SHAMap.h | 7 +++-- .../module/app/shamap/SHAMapTreeNode.cpp | 1 - src/ripple/module/app/shamap/SHAMapTreeNode.h | 9 ++---- 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/ripple/module/app/shamap/SHAMap.cpp b/src/ripple/module/app/shamap/SHAMap.cpp index ab7142e4701..e3680ab38f7 100644 --- a/src/ripple/module/app/shamap/SHAMap.cpp +++ b/src/ripple/module/app/shamap/SHAMap.cpp @@ -117,12 +117,12 @@ SHAMap::pointer SHAMap::snapShot (bool isMutable) return ret; } -std::stack> +SHAMap::SharedPtrNodeStack SHAMap::getStack (uint256 const& id, bool include_nonmatching_leaf) { // Walk the tree as far as possible to the specified identifier // produce a stack of nodes along the way, with the terminal node at the top - std::stack > stack; + SharedPtrNodeStack stack; SHAMapTreeNode::pointer node = root; SHAMapNodeID nodeID; @@ -147,7 +147,7 @@ SHAMap::getStack (uint256 const& id, bool include_nonmatching_leaf) } void -SHAMap::dirtyUp (std::stack>& stack, +SHAMap::dirtyUp (SharedPtrNodeStack& stack, uint256 const& target, SHAMapTreeNode::pointer child) { // walk the tree up from through the inner nodes to the root @@ -522,7 +522,7 @@ SHAMap::onlyBelow (SHAMapTreeNode* node) if (!node->isEmptyBranch (i)) { if (nextNode) - return false; + return SHAMap::pointer (); nextNode = descendThrow (node, i); } @@ -587,8 +587,8 @@ SHAMapItem::pointer SHAMap::peekNextItem (uint256 const& id, SHAMapTreeNode::TNT { // Get a pointer to the next item in the tree after a given item - item need not be in tree - std::stack> stack = - getStack (id, true); + auto stack = getStack (id, true); + while (!stack.empty ()) { SHAMapTreeNode* node = stack.top().first.get(); @@ -628,8 +628,8 @@ SHAMapItem::pointer SHAMap::peekNextItem (uint256 const& id, SHAMapTreeNode::TNT // Get a pointer to the previous item in the tree after a given item - item need not be in tree SHAMapItem::pointer SHAMap::peekPrevItem (uint256 const& id) { - std::stack> stack = - getStack (id, true); + auto stack = getStack (id, true); + while (!stack.empty ()) { SHAMapTreeNode* node = stack.top ().first.get(); @@ -704,8 +704,7 @@ bool SHAMap::delItem (uint256 const& id) // delete the item with this ID assert (mState != smsImmutable); - std::stack > stack = - getStack (id, true); + auto stack = getStack (id, true); if (stack.empty ()) throw (std::runtime_error ("missing node")); @@ -758,7 +757,7 @@ bool SHAMap::delItem (uint256 const& id) if (item) { - for (int i = 0; i > 16; ++i) + for (int i = 0; i < 16; ++i) { if (!node->isEmptyBranch (i)) { @@ -798,8 +797,8 @@ bool SHAMap::addGiveItem (SHAMapItem::ref item, bool isTransaction, bool hasMeta assert (mState != smsImmutable); - std::stack> stack = - getStack (tag, true); + auto stack = getStack (tag, true); + if (stack.empty ()) throw (std::runtime_error ("missing node")); @@ -879,8 +878,8 @@ bool SHAMap::updateGiveItem (SHAMapItem::ref item, bool isTransaction, bool hasM assert (mState != smsImmutable); - std::stack> stack = - getStack (tag, true); + auto stack = getStack (tag, true); + if (stack.empty ()) throw (std::runtime_error ("missing node")); diff --git a/src/ripple/module/app/shamap/SHAMap.h b/src/ripple/module/app/shamap/SHAMap.h index 20dcd31c188..8b947337172 100644 --- a/src/ripple/module/app/shamap/SHAMap.h +++ b/src/ripple/module/app/shamap/SHAMap.h @@ -1,3 +1,4 @@ + //------------------------------------------------------------------------------ /* This file is part of rippled: https://github.com/ripple/rippled @@ -115,6 +116,8 @@ class SHAMap typedef std::map Delta; typedef hash_map NodeMap; + typedef std::stack> SharedPtrNodeStack; + public: // build new map SHAMap ( @@ -254,11 +257,11 @@ class SHAMap SHAMapTreeNode::pointer fetchNode (uint256 const& hash); /** Update hashes up to the root */ - void dirtyUp (std::stack>& stack, + void dirtyUp (SharedPtrNodeStack& stack, uint256 const& target, SHAMapTreeNode::pointer terminal); /** Get the path from the root to the specified node */ - std::stack> + SharedPtrNodeStack getStack (uint256 const& id, bool include_nonmatching_leaf); /** Walk to the specified index, returning the node */ diff --git a/src/ripple/module/app/shamap/SHAMapTreeNode.cpp b/src/ripple/module/app/shamap/SHAMapTreeNode.cpp index 6f39eb7c8bb..c4c21c552b3 100644 --- a/src/ripple/module/app/shamap/SHAMapTreeNode.cpp +++ b/src/ripple/module/app/shamap/SHAMapTreeNode.cpp @@ -23,7 +23,6 @@ std::mutex SHAMapTreeNode::childLock; SHAMapTreeNode::SHAMapTreeNode (std::uint32_t seq) : mSeq (seq) - , mAccessSeq (seq) , mType (tnERROR) , mIsBranch (0) , mFullBelow (false) diff --git a/src/ripple/module/app/shamap/SHAMapTreeNode.h b/src/ripple/module/app/shamap/SHAMapTreeNode.h index 3818cb2b6f2..842845a7a84 100644 --- a/src/ripple/module/app/shamap/SHAMapTreeNode.h +++ b/src/ripple/module/app/shamap/SHAMapTreeNode.h @@ -76,12 +76,7 @@ class SHAMapTreeNode } void setSeq (std::uint32_t s) { - mAccessSeq = mSeq = s; - } - void touch (std::uint32_t s) - { - if (mSeq != 0) - mAccessSeq = s; + mSeq = s; } uint256 const& getNodeHash () const { @@ -196,7 +191,7 @@ class SHAMapTreeNode uint256 mHashes[16]; SHAMapTreeNode::pointer mChildren[16]; SHAMapItem::pointer mItem; - std::uint32_t mSeq, mAccessSeq; + std::uint32_t mSeq; TNType mType; int mIsBranch; bool mFullBelow;