diff --git a/src/ripple/shamap/SHAMap.h b/src/ripple/shamap/SHAMap.h index fe022d584..b7ada5afd 100644 --- a/src/ripple/shamap/SHAMap.h +++ b/src/ripple/shamap/SHAMap.h @@ -79,9 +79,6 @@ using MissingNodeHandler = std::function ; class SHAMap { private: - using NodeStack = std::stack, - std::vector>>; - Family& f_; beast::Journal journal_; std::uint32_t seq_; @@ -243,7 +240,7 @@ private: /** Walk towards the specified id, returning the node. Caller must check if the return is nullptr, and if not, if the node->peekItem()->key() == id */ SHAMapTreeNode* - walkTowardsKey(uint256 const& id, NodeStack* stack = nullptr) const; + walkTowardsKey(uint256 const& id, SharedPtrNodeStack* stack = nullptr) const; /** Return nullptr if key not found */ SHAMapTreeNode* findKey(uint256 const& id) const; @@ -263,7 +260,8 @@ private: writeNode(NodeObjectType t, std::uint32_t seq, std::shared_ptr node) const; - SHAMapTreeNode* firstBelow (SHAMapAbstractNode*, NodeStack& stack) const; + SHAMapTreeNode* firstBelow (std::shared_ptr, + SharedPtrNodeStack& stack) const; // Simple descent // Get a child of the specified node @@ -291,8 +289,8 @@ private: bool hasInnerNode (SHAMapNodeID const& nodeID, SHAMapHash const& hash) const; bool hasLeafNode (uint256 const& tag, SHAMapHash const& hash) const; - SHAMapItem const* peekFirstItem(NodeStack& stack) const; - SHAMapItem const* peekNextItem(uint256 const& id, NodeStack& stack) const; + SHAMapItem const* peekFirstItem(SharedPtrNodeStack& stack) const; + SHAMapItem const* peekNextItem(uint256 const& id, SharedPtrNodeStack& stack) const; bool walkBranch (SHAMapAbstractNode* node, std::shared_ptr const& otherMapItem, bool isFirstMap, Delta & differences, int & maxCount) const; @@ -361,9 +359,9 @@ public: using pointer = value_type const*; private: - NodeStack stack_; - SHAMap const* map_ = nullptr; - pointer item_ = nullptr; + SharedPtrNodeStack stack_; + SHAMap const* map_ = nullptr; + pointer item_ = nullptr; public: const_iterator() = default; @@ -377,7 +375,7 @@ public: private: explicit const_iterator(SHAMap const* map); const_iterator(SHAMap const* map, pointer item); - const_iterator(SHAMap const* map, pointer item, NodeStack&& stack); + const_iterator(SHAMap const* map, pointer item, SharedPtrNodeStack&& stack); friend bool operator==(const_iterator const& x, const_iterator const& y); friend class SHAMap; @@ -399,7 +397,7 @@ SHAMap::const_iterator::const_iterator(SHAMap const* map, pointer item) inline SHAMap::const_iterator::const_iterator(SHAMap const* map, pointer item, - NodeStack&& stack) + SharedPtrNodeStack&& stack) : stack_(std::move(stack)) , map_(map) , item_(item) diff --git a/src/ripple/shamap/impl/SHAMap.cpp b/src/ripple/shamap/impl/SHAMap.cpp index d3a5266ea..220a3f660 100644 --- a/src/ripple/shamap/impl/SHAMap.cpp +++ b/src/ripple/shamap/impl/SHAMap.cpp @@ -145,10 +145,10 @@ SHAMap::dirtyUp (SharedPtrNodeStack& stack, } SHAMapTreeNode* -SHAMap::walkTowardsKey(uint256 const& id, NodeStack* stack) const +SHAMap::walkTowardsKey(uint256 const& id, SharedPtrNodeStack* stack) const { assert(stack == nullptr || stack->empty()); - auto inNode = root_.get(); + auto inNode = root_; SHAMapNodeID nodeID; if (stack != nullptr) stack->push({inNode, nodeID}); @@ -156,7 +156,7 @@ SHAMap::walkTowardsKey(uint256 const& id, NodeStack* stack) const while (inNode->isInner()) { auto const branch = nodeID.selectBranch (id); - auto const inner = static_cast(inNode); + auto const inner = std::static_pointer_cast(inNode); if (inner->isEmptyBranch (branch)) return nullptr; @@ -165,7 +165,7 @@ SHAMap::walkTowardsKey(uint256 const& id, NodeStack* stack) const if (stack != nullptr) stack->push({inNode, nodeID}); } - return static_cast(inNode); + return static_cast(inNode.get()); } SHAMapTreeNode* @@ -430,12 +430,13 @@ SHAMap::unshareNode (std::shared_ptr node, SHAMapNodeID const& nodeID) } SHAMapTreeNode* -SHAMap::firstBelow(SHAMapAbstractNode* node, NodeStack& stack) const +SHAMap::firstBelow(std::shared_ptr node, + SharedPtrNodeStack& stack) const { // Return the first item at or below this node if (node->isLeaf()) - return static_cast(node); - auto inner = static_cast(node); + return static_cast(node.get()); + auto inner = std::static_pointer_cast(node); for (int i = 0; i < 16;) { if (!inner->isEmptyBranch(i)) @@ -444,8 +445,8 @@ SHAMap::firstBelow(SHAMapAbstractNode* node, NodeStack& stack) const assert(!stack.empty()); stack.push({node, stack.top().second.getChildNodeID(i)}); if (node->isLeaf()) - return static_cast(node); - inner = static_cast(node); + return static_cast(node.get()); + inner = std::static_pointer_cast(node); i = 0; // scan all 16 branches of this new node } else @@ -497,11 +498,11 @@ static std::shared_ptr< SHAMapItem const> const nullConstSHAMapItem; SHAMapItem const* -SHAMap::peekFirstItem(NodeStack& stack) const +SHAMap::peekFirstItem(SharedPtrNodeStack& stack) const { assert(stack.empty()); - stack.push({root_.get(), SHAMapNodeID{}}); - SHAMapTreeNode* node = firstBelow(root_.get(), stack); + stack.push({root_, SHAMapNodeID{}}); + SHAMapTreeNode* node = firstBelow(root_, stack); if (!node) { while (!stack.empty()) @@ -512,7 +513,7 @@ SHAMap::peekFirstItem(NodeStack& stack) const } SHAMapItem const* -SHAMap::peekNextItem(uint256 const& id, NodeStack& stack) const +SHAMap::peekNextItem(uint256 const& id, SharedPtrNodeStack& stack) const { assert(!stack.empty()); assert(stack.top().first->isLeaf()); @@ -522,7 +523,7 @@ SHAMap::peekNextItem(uint256 const& id, NodeStack& stack) const auto node = stack.top().first; auto nodeID = stack.top().second; assert(!node->isLeaf()); - auto inner = static_cast(node); + auto inner = std::static_pointer_cast(node); for (auto i = nodeID.selectBranch(id) + 1; i < 16; ++i) { if (!inner->isEmptyBranch(i)) @@ -583,22 +584,22 @@ SHAMap::upper_bound(uint256 const& id) const { // Get a const_iterator to the next item in the tree after a given item // item need not be in tree - NodeStack stack; + SharedPtrNodeStack stack; walkTowardsKey(id, &stack); - SHAMapAbstractNode* node; + std::shared_ptr node; SHAMapNodeID nodeID; while (!stack.empty()) { std::tie(node, nodeID) = stack.top(); if (node->isLeaf()) { - auto leaf = static_cast(node); + auto leaf = static_cast(node.get()); if (leaf->peekItem()->key() > id) return const_iterator(this, leaf->peekItem().get(), std::move(stack)); } else { - auto inner = static_cast(node); + auto inner = std::static_pointer_cast(node); for (auto branch = nodeID.selectBranch(id) + 1; branch < 16; ++branch) { if (!inner->isEmptyBranch(branch))