Prevent unnecessary shared_ptr copies by accepting a value in SHAMapInnerNode::setChild (#4266)

* Do a move instead of a copy in `SHAMapInnerNode::setChild`

* Create the value directly in the call
This commit is contained in:
Gregory Popovitch
2022-12-08 23:15:21 -05:00
committed by Richard Holland
parent c912b939d6
commit d46664df0f
3 changed files with 6 additions and 7 deletions

View File

@@ -284,7 +284,7 @@ SHAMapInnerNode::getString(const SHAMapNodeID& id) const
// We are modifying an inner node
void
SHAMapInnerNode::setChild(int m, std::shared_ptr<SHAMapTreeNode> const& child)
SHAMapInnerNode::setChild(int m, std::shared_ptr<SHAMapTreeNode> child)
{
assert((m >= 0) && (m < branchFactor));
assert(cowid_ != 0);
@@ -310,7 +310,7 @@ SHAMapInnerNode::setChild(int m, std::shared_ptr<SHAMapTreeNode> 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();