From 397f5efdc6851097d7d0ec61391d4d67ffdb11f2 Mon Sep 17 00:00:00 2001 From: greg7mdp Date: Thu, 21 Jul 2022 14:12:20 -0400 Subject: [PATCH] Do a move instead of a copy in `SHAMapInnerNode::setChild` --- src/ripple/shamap/SHAMapInnerNode.h | 2 +- src/ripple/shamap/impl/SHAMap.cpp | 6 +++--- src/ripple/shamap/impl/SHAMapInnerNode.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ripple/shamap/SHAMapInnerNode.h b/src/ripple/shamap/SHAMapInnerNode.h index 5f0765e9c26..c85cdcbbc85 100644 --- a/src/ripple/shamap/SHAMapInnerNode.h +++ b/src/ripple/shamap/SHAMapInnerNode.h @@ -147,7 +147,7 @@ class SHAMapInnerNode final : public SHAMapTreeNode, getChildHash(int m) const; void - setChild(int m, std::shared_ptr const& child); + setChild(int m, std::shared_ptr child); void shareChild(int m, std::shared_ptr const& child); diff --git a/src/ripple/shamap/impl/SHAMap.cpp b/src/ripple/shamap/impl/SHAMap.cpp index 6f6acb9a7e1..d68d3896f13 100644 --- a/src/ripple/shamap/impl/SHAMap.cpp +++ b/src/ripple/shamap/impl/SHAMap.cpp @@ -118,7 +118,7 @@ SHAMap::dirtyUp( assert(branch >= 0); node = unshareNode(std::move(node), nodeID); - node->setChild(branch, child); + node->setChild(branch, std::move(child)); child = std::move(node); } @@ -718,7 +718,7 @@ SHAMap::delItem(uint256 const& id) stack.pop(); node = unshareNode(std::move(node), nodeID); - node->setChild(selectBranch(nodeID, id), prevNode); + node->setChild(selectBranch(nodeID, id), std::move(prevNode)); if (!nodeID.isRoot()) { @@ -796,7 +796,7 @@ SHAMap::addGiveItem(SHAMapNodeType type, std::shared_ptr item) int branch = selectBranch(nodeID, tag); assert(inner->isEmptyBranch(branch)); auto newNode = makeTypedLeaf(type, std::move(item), cowid_); - inner->setChild(branch, newNode); + inner->setChild(branch, std::move(newNode)); } else { diff --git a/src/ripple/shamap/impl/SHAMapInnerNode.cpp b/src/ripple/shamap/impl/SHAMapInnerNode.cpp index d408fe195f1..6ea6f47eb37 100644 --- a/src/ripple/shamap/impl/SHAMapInnerNode.cpp +++ b/src/ripple/shamap/impl/SHAMapInnerNode.cpp @@ -284,7 +284,7 @@ SHAMapInnerNode::getString(const SHAMapNodeID& id) const // We are modifying an inner node void -SHAMapInnerNode::setChild(int m, std::shared_ptr const& child) +SHAMapInnerNode::setChild(int m, std::shared_ptr child) { assert((m >= 0) && (m < branchFactor)); assert(cowid_ != 0); @@ -310,7 +310,7 @@ SHAMapInnerNode::setChild(int m, std::shared_ptr const& child) auto const childIndex = *getChildIndex(m); auto [_, hashes, children] = hashesAndChildren_.getHashesAndChildren(); hashes[childIndex].zero(); - children[childIndex] = child; + children[childIndex] = std::move(child); } hash_.zero();