From 6d28f2a8d9038715201915844007f40f63ed249f Mon Sep 17 00:00:00 2001 From: seelabs Date: Fri, 10 Apr 2020 14:07:31 -0400 Subject: [PATCH] Cleanup code using move semantics --- src/ripple/app/ledger/Ledger.cpp | 4 +- src/ripple/app/ledger/impl/LedgerReplay.cpp | 2 +- src/ripple/app/misc/FeeVoteImpl.cpp | 2 +- src/ripple/app/misc/NetworkOPs.cpp | 8 +-- src/ripple/app/misc/impl/AccountTxPaging.cpp | 22 ++++--- src/ripple/app/misc/impl/AccountTxPaging.h | 8 +-- src/ripple/app/misc/impl/TxQ.cpp | 2 +- src/ripple/app/misc/impl/ValidatorKeys.cpp | 3 +- src/ripple/app/misc/impl/ValidatorList.cpp | 2 +- src/ripple/nodestore/impl/Shard.cpp | 2 +- src/ripple/overlay/impl/OverlayImpl.cpp | 6 +- src/ripple/overlay/impl/PeerImp.cpp | 3 +- src/ripple/protocol/impl/STAmount.cpp | 2 +- src/ripple/rpc/impl/DeliveredAmount.cpp | 10 +--- src/ripple/rpc/impl/ShardArchiveHandler.cpp | 63 ++++++++++---------- src/ripple/rpc/impl/TransactionSign.cpp | 6 +- src/ripple/shamap/SHAMap.h | 4 +- src/ripple/shamap/SHAMapTreeNode.h | 6 +- src/ripple/shamap/impl/SHAMap.cpp | 18 +++--- src/ripple/shamap/impl/SHAMapSync.cpp | 14 +++-- src/ripple/shamap/impl/SHAMapTreeNode.cpp | 42 ++++++------- src/test/app/Manifest_test.cpp | 13 ++-- src/test/app/Regression_test.cpp | 2 +- src/test/jtx/impl/Account.cpp | 2 +- src/test/ledger/View_test.cpp | 2 +- 25 files changed, 132 insertions(+), 116 deletions(-) diff --git a/src/ripple/app/ledger/Ledger.cpp b/src/ripple/app/ledger/Ledger.cpp index 0f95bdfb85..d00097d550 100644 --- a/src/ripple/app/ledger/Ledger.cpp +++ b/src/ripple/app/ledger/Ledger.cpp @@ -499,7 +499,7 @@ Ledger::rawInsert(std::shared_ptr const& sle) Serializer ss; sle->add(ss); auto item = std::make_shared(sle->key(), std::move(ss)); - // VFALCO NOTE addGiveItem should take ownership + // addGiveItem should take ownership if (!stateMap_->addGiveItem(std::move(item), false, false)) LogicError("Ledger::rawInsert: key already exists"); } @@ -510,7 +510,7 @@ Ledger::rawReplace(std::shared_ptr const& sle) Serializer ss; sle->add(ss); auto item = std::make_shared(sle->key(), std::move(ss)); - // VFALCO NOTE updateGiveItem should take ownership + // updateGiveItem should take ownership if (!stateMap_->updateGiveItem(std::move(item), false, false)) LogicError("Ledger::rawReplace: key not found"); } diff --git a/src/ripple/app/ledger/impl/LedgerReplay.cpp b/src/ripple/app/ledger/impl/LedgerReplay.cpp index d9dfd1d7f8..21f4c6b306 100644 --- a/src/ripple/app/ledger/impl/LedgerReplay.cpp +++ b/src/ripple/app/ledger/impl/LedgerReplay.cpp @@ -29,7 +29,7 @@ LedgerReplay::LedgerReplay( { for (auto const& item : replay_->txMap()) { - auto const txPair = replay_->txRead(item.key()); + auto txPair = replay_->txRead(item.key()); // non-const so can be moved auto const txIndex = (*txPair.second)[sfTransactionIndex]; orderedTxns_.emplace(txIndex, std::move(txPair.first)); } diff --git a/src/ripple/app/misc/FeeVoteImpl.cpp b/src/ripple/app/misc/FeeVoteImpl.cpp index ce3da19b2d..873c488754 100644 --- a/src/ripple/app/misc/FeeVoteImpl.cpp +++ b/src/ripple/app/misc/FeeVoteImpl.cpp @@ -245,7 +245,7 @@ FeeVoteImpl::doVoting( auto tItem = std::make_shared(txID, s.peekData()); - if (!initialPosition->addGiveItem(tItem, true, false)) + if (!initialPosition->addGiveItem(std::move(tItem), true, false)) { JLOG(journal_.warn()) << "Ledger already had fee change"; } diff --git a/src/ripple/app/misc/NetworkOPs.cpp b/src/ripple/app/misc/NetworkOPs.cpp index 28afc7dfb9..06400e4041 100644 --- a/src/ripple/app/misc/NetworkOPs.cpp +++ b/src/ripple/app/misc/NetworkOPs.cpp @@ -2405,8 +2405,8 @@ NetworkOPsImp::getTxsAccount( auto bound = [&ret, &app]( std::uint32_t ledger_index, std::string const& status, - Blob const& rawTxn, - Blob const& rawMeta) { + Blob&& rawTxn, + Blob&& rawMeta) { convertBlobsToTxResult(ret, ledger_index, status, rawTxn, rawMeta, app); }; @@ -2444,8 +2444,8 @@ NetworkOPsImp::getTxsAccountB( auto bound = [&ret]( std::uint32_t ledgerIndex, std::string const& status, - Blob const& rawTxn, - Blob const& rawMeta) { + Blob&& rawTxn, + Blob&& rawMeta) { ret.emplace_back(std::move(rawTxn), std::move(rawMeta), ledgerIndex); }; diff --git a/src/ripple/app/misc/impl/AccountTxPaging.cpp b/src/ripple/app/misc/impl/AccountTxPaging.cpp index 317178c4d7..7acf37c8a9 100644 --- a/src/ripple/app/misc/impl/AccountTxPaging.cpp +++ b/src/ripple/app/misc/impl/AccountTxPaging.cpp @@ -65,11 +65,9 @@ accountTxPage( DatabaseCon& connection, AccountIDCache const& idCache, std::function const& onUnsavedLedger, - std::function const& onTransaction, + std::function< + void(std::uint32_t, std::string const&, Blob&&, Blob&&)> const& + onTransaction, AccountID const& account, std::int32_t minLedger, std::int32_t maxLedger, @@ -247,11 +245,21 @@ accountTxPage( if (rawMeta.size() == 0) onUnsavedLedger(ledgerSeq.value_or(0)); + // `rawData` and `rawMeta` will be used after they are moved. + // That's OK. onTransaction( rangeCheckedCast(ledgerSeq.value_or(0)), *status, - rawData, - rawMeta); + std::move(rawData), + std::move(rawMeta)); + // Note some callbacks will move the data, some will not. Clear + // them so code doesn't depend on if the data was actually moved + // or not. The code will be more efficient if `rawData` and + // `rawMeta` don't have to allocate in `convert`, so don't + // refactor my moving these variables into loop scope. + rawData.clear(); + rawMeta.clear(); + --numberOfResults; } } diff --git a/src/ripple/app/misc/impl/AccountTxPaging.h b/src/ripple/app/misc/impl/AccountTxPaging.h index 36dfeabf3a..5a6324cd53 100644 --- a/src/ripple/app/misc/impl/AccountTxPaging.h +++ b/src/ripple/app/misc/impl/AccountTxPaging.h @@ -47,11 +47,9 @@ accountTxPage( DatabaseCon& connection, AccountIDCache const& idCache, std::function const& onUnsavedLedger, - std::function const& onTransaction, + std::function< + void(std::uint32_t, std::string const&, Blob&&, Blob&&)> const& + onTransaction, AccountID const& account, std::int32_t minLedger, std::int32_t maxLedger, diff --git a/src/ripple/app/misc/impl/TxQ.cpp b/src/ripple/app/misc/impl/TxQ.cpp index ed967ddd2d..d2d9fa0bde 100644 --- a/src/ripple/app/misc/impl/TxQ.cpp +++ b/src/ripple/app/misc/impl/TxQ.cpp @@ -1552,7 +1552,7 @@ setup_TxQ(Config const& config) std::unique_ptr make_TxQ(TxQ::Setup const& setup, beast::Journal j) { - return std::make_unique(setup, std::move(j)); + return std::make_unique(setup, j); } } // namespace ripple diff --git a/src/ripple/app/misc/impl/ValidatorKeys.cpp b/src/ripple/app/misc/impl/ValidatorKeys.cpp index fa095645f8..9140cdbde6 100644 --- a/src/ripple/app/misc/impl/ValidatorKeys.cpp +++ b/src/ripple/app/misc/impl/ValidatorKeys.cpp @@ -39,7 +39,8 @@ ValidatorKeys::ValidatorKeys(Config const& config, beast::Journal j) if (config.exists(SECTION_VALIDATOR_TOKEN)) { - if (auto const token = loadValidatorToken( + // token is non-const so it can be moved from + if (auto token = loadValidatorToken( config.section(SECTION_VALIDATOR_TOKEN).lines())) { auto const pk = diff --git a/src/ripple/app/misc/impl/ValidatorList.cpp b/src/ripple/app/misc/impl/ValidatorList.cpp index 4712483325..710ad34928 100644 --- a/src/ripple/app/misc/impl/ValidatorList.cpp +++ b/src/ripple/app/misc/impl/ValidatorList.cpp @@ -183,7 +183,7 @@ ValidatorList::load( // Config listed keys never expire if (it.second) it.first->second.expiration = TimeKeeper::time_point::max(); - it.first->second.list.emplace_back(std::move(*id)); + it.first->second.list.emplace_back(*id); it.first->second.available = true; ++count; } diff --git a/src/ripple/nodestore/impl/Shard.cpp b/src/ripple/nodestore/impl/Shard.cpp index 71f2af65a6..1701206fe4 100644 --- a/src/ripple/nodestore/impl/Shard.cpp +++ b/src/ripple/nodestore/impl/Shard.cpp @@ -812,7 +812,7 @@ Shard::storeSQLite( session << (STTx::getMetaSQLInsertReplaceHeader() + item.first->getMetaSQL( - seq, sqlEscape(std::move(s.modData()))) + + seq, sqlEscape(s.modData())) + ';'); } } diff --git a/src/ripple/overlay/impl/OverlayImpl.cpp b/src/ripple/overlay/impl/OverlayImpl.cpp index 9531382060..44912c9ce2 100644 --- a/src/ripple/overlay/impl/OverlayImpl.cpp +++ b/src/ripple/overlay/impl/OverlayImpl.cpp @@ -809,7 +809,8 @@ OverlayImpl::crawlShards(bool pubKey, std::uint32_t hops) for_each([&](std::shared_ptr const& peer) { if (auto psi = peer->getPeerShardInfo()) { - for (auto const& e : *psi) + // e is non-const so it may be moved from + for (auto& e : *psi) { auto it{peerShardInfo.find(e.first)}; if (it != peerShardInfo.end()) @@ -898,7 +899,8 @@ OverlayImpl::getOverlayInfo() { auto version{sp->getVersion()}; if (!version.empty()) - pv[jss::version] = std::move(version); + // Could move here if Json::value supported moving from strings + pv[jss::version] = version; } std::uint32_t minSeq, maxSeq; diff --git a/src/ripple/overlay/impl/PeerImp.cpp b/src/ripple/overlay/impl/PeerImp.cpp index c08c023cd3..cfcc8ef0c5 100644 --- a/src/ripple/overlay/impl/PeerImp.cpp +++ b/src/ripple/overlay/impl/PeerImp.cpp @@ -322,7 +322,8 @@ PeerImp::json() std::string name{getName()}; if (!name.empty()) - ret[jss::name] = std::move(name); + // Could move here if Json::Value supported moving from a string + ret[jss::name] = name; } ret[jss::load] = usage_.balance(); diff --git a/src/ripple/protocol/impl/STAmount.cpp b/src/ripple/protocol/impl/STAmount.cpp index d3e38812b4..37a010c3f3 100644 --- a/src/ripple/protocol/impl/STAmount.cpp +++ b/src/ripple/protocol/impl/STAmount.cpp @@ -423,7 +423,7 @@ std::uint64_t const STAmount::uRateOne = getRate(STAmount(1), STAmount(1)); void STAmount::setIssue(Issue const& issue) { - mIssue = std::move(issue); + mIssue = issue; mIsNative = isXRP(*this); } diff --git a/src/ripple/rpc/impl/DeliveredAmount.cpp b/src/ripple/rpc/impl/DeliveredAmount.cpp index 6f0ed94be1..6a543430e1 100644 --- a/src/ripple/rpc/impl/DeliveredAmount.cpp +++ b/src/ripple/rpc/impl/DeliveredAmount.cpp @@ -148,10 +148,7 @@ insertDeliveredAmount( auto const getCloseTime = [&info] { return info.closeTime; }; auto amt = getDeliveredAmount( - getLedgerIndex, - getCloseTime, - std::move(serializedTx), - transactionMeta); + getLedgerIndex, getCloseTime, serializedTx, transactionMeta); if (amt) { meta[jss::delivered_amount] = @@ -182,10 +179,7 @@ getDeliveredAmount( return context.ledgerMaster.getCloseTimeBySeq(getLedgerIndex()); }; return getDeliveredAmount( - getLedgerIndex, - getCloseTime, - std::move(serializedTx), - transactionMeta); + getLedgerIndex, getCloseTime, serializedTx, transactionMeta); } return {}; diff --git a/src/ripple/rpc/impl/ShardArchiveHandler.cpp b/src/ripple/rpc/impl/ShardArchiveHandler.cpp index 54a0dd6357..dac964a302 100644 --- a/src/ripple/rpc/impl/ShardArchiveHandler.cpp +++ b/src/ripple/rpc/impl/ShardArchiveHandler.cpp @@ -424,40 +424,43 @@ ShardArchiveHandler::complete(path dstPath) } } - auto wrapper = jobCounter_.wrap([=, dstPath = std::move(dstPath)](Job&) { - if (isStopping()) - return; + // Make lambdas mutable captured vars can be moved from + auto wrapper = + jobCounter_.wrap([=, dstPath = std::move(dstPath)](Job&) mutable { + if (isStopping()) + return; - // If not synced then defer and retry - auto const mode{app_.getOPs().getOperatingMode()}; - if (mode != OperatingMode::FULL) - { - std::lock_guard lock(m_); - timer_.expires_from_now(static_cast( - (static_cast(OperatingMode::FULL) - - static_cast(mode)) * - 10)); + // If not synced then defer and retry + auto const mode{app_.getOPs().getOperatingMode()}; + if (mode != OperatingMode::FULL) + { + std::lock_guard lock(m_); + timer_.expires_from_now(static_cast( + (static_cast(OperatingMode::FULL) - + static_cast(mode)) * + 10)); - auto wrapper = - timerCounter_.wrap([=, dstPath = std::move(dstPath)]( - boost::system::error_code const& ec) { - if (ec != boost::asio::error::operation_aborted) - complete(std::move(dstPath)); - }); + auto wrapper = timerCounter_.wrap( + [=, dstPath = std::move(dstPath)]( + boost::system::error_code const& ec) mutable { + if (ec != boost::asio::error::operation_aborted) + complete(std::move(dstPath)); + }); - if (!wrapper) - onClosureFailed( - "failed to wrap closure for operating mode timer", lock); + if (!wrapper) + onClosureFailed( + "failed to wrap closure for operating mode timer", + lock); + else + timer_.async_wait(*wrapper); + } else - timer_.async_wait(*wrapper); - } - else - { - process(dstPath); - std::lock_guard lock(m_); - removeAndProceed(lock); - } - }); + { + process(dstPath); + std::lock_guard lock(m_); + removeAndProceed(lock); + } + }); if (!wrapper) { diff --git a/src/ripple/rpc/impl/TransactionSign.cpp b/src/ripple/rpc/impl/TransactionSign.cpp index 345d71ffd2..0ebeef3632 100644 --- a/src/ripple/rpc/impl/TransactionSign.cpp +++ b/src/ripple/rpc/impl/TransactionSign.cpp @@ -335,11 +335,7 @@ struct transactionPreProcessResult transactionPreProcessResult() = delete; transactionPreProcessResult(transactionPreProcessResult const&) = delete; - transactionPreProcessResult(transactionPreProcessResult&& rhs) - : first(std::move(rhs.first)) // VS2013 won't default this. - , second(std::move(rhs.second)) - { - } + transactionPreProcessResult(transactionPreProcessResult&& rhs) = default; transactionPreProcessResult& operator=(transactionPreProcessResult const&) = delete; diff --git a/src/ripple/shamap/SHAMap.h b/src/ripple/shamap/SHAMap.h index 4f962826fb..67b3c3c560 100644 --- a/src/ripple/shamap/SHAMap.h +++ b/src/ripple/shamap/SHAMap.h @@ -165,12 +165,12 @@ public: // save a copy if you have a temporary anyway bool updateGiveItem( - std::shared_ptr const&, + std::shared_ptr, bool isTransaction, bool hasMeta); bool addGiveItem( - std::shared_ptr const&, + std::shared_ptr, bool isTransaction, bool hasMeta); diff --git a/src/ripple/shamap/SHAMapTreeNode.h b/src/ripple/shamap/SHAMapTreeNode.h index f3bef2569b..93cb91fe03 100644 --- a/src/ripple/shamap/SHAMapTreeNode.h +++ b/src/ripple/shamap/SHAMapTreeNode.h @@ -263,11 +263,11 @@ public: operator=(const SHAMapTreeNode&) = delete; SHAMapTreeNode( - std::shared_ptr const& item, + std::shared_ptr item, TNType type, std::uint32_t seq); SHAMapTreeNode( - std::shared_ptr const& item, + std::shared_ptr item, TNType type, std::uint32_t seq, SHAMapHash const& hash); @@ -292,7 +292,7 @@ public: // public only to SHAMap std::shared_ptr const& peekItem() const; bool - setItem(std::shared_ptr const& i, TNType type); + setItem(std::shared_ptr i, TNType type); std::string getString(SHAMapNodeID const&) const override; diff --git a/src/ripple/shamap/impl/SHAMap.cpp b/src/ripple/shamap/impl/SHAMap.cpp index 03e301d75f..b1d390b1cc 100644 --- a/src/ripple/shamap/impl/SHAMap.cpp +++ b/src/ripple/shamap/impl/SHAMap.cpp @@ -697,7 +697,7 @@ SHAMap::delItem(uint256 const& id) bool SHAMap::addGiveItem( - std::shared_ptr const& item, + std::shared_ptr item, bool isTransaction, bool hasMeta) { @@ -732,7 +732,8 @@ SHAMap::addGiveItem( auto inner = std::static_pointer_cast(node); int branch = nodeID.selectBranch(tag); assert(inner->isEmptyBranch(branch)); - auto newNode = std::make_shared(item, type, seq_); + auto newNode = + std::make_shared(std::move(item), type, seq_); inner->setChild(branch, newNode); } else @@ -762,12 +763,13 @@ SHAMap::addGiveItem( assert(node->isInner()); std::shared_ptr newNode = - std::make_shared(item, type, seq_); + std::make_shared(std::move(item), type, seq_); assert(newNode->isValid() && newNode->isLeaf()); auto inner = std::static_pointer_cast(node); inner->setChild(b1, newNode); - newNode = std::make_shared(otherItem, type, seq_); + newNode = + std::make_shared(std::move(otherItem), type, seq_); assert(newNode->isValid() && newNode->isLeaf()); inner->setChild(b2, newNode); } @@ -799,7 +801,7 @@ SHAMap::getHash() const bool SHAMap::updateGiveItem( - std::shared_ptr const& item, + std::shared_ptr item, bool isTransaction, bool hasMeta) { @@ -827,7 +829,7 @@ SHAMap::updateGiveItem( node = unshareNode(std::move(node), nodeID); if (!node->setItem( - item, + std::move(item), !isTransaction ? SHAMapTreeNode::tnACCOUNT_STATE : (hasMeta ? SHAMapTreeNode::tnTRANSACTION_MD : SHAMapTreeNode::tnTRANSACTION_NM))) @@ -1005,7 +1007,9 @@ SHAMap::walkSubTree(bool doWrite, NodeObjectType t, std::uint32_t seq) // save our place and work on this node stack.emplace(std::move(node), branch); - + // The semantics of this changes when we move to c++-20 + // Right now no move will occur; With c++-20 child will + // be moved from. node = std::static_pointer_cast( std::move(child)); pos = 0; diff --git a/src/ripple/shamap/impl/SHAMapSync.cpp b/src/ripple/shamap/impl/SHAMapSync.cpp index 6164bd98dc..b62ca050b6 100644 --- a/src/ripple/shamap/impl/SHAMapSync.cpp +++ b/src/ripple/shamap/impl/SHAMapSync.cpp @@ -485,11 +485,13 @@ SHAMap::getNodeFat( std::tie(node, nodeID, depth) = stack.top(); stack.pop(); - // Add this node to the reply - Serializer s; - node->addRaw(s, snfWIRE); - nodeIDs.push_back(nodeID); - rawNodes.push_back(std::move(s.peekData())); + { + // Add this node to the reply + Serializer s; + node->addRaw(s, snfWIRE); + nodeIDs.push_back(nodeID); + rawNodes.push_back(std::move(s.modData())); + } if (node->isInner()) { @@ -522,7 +524,7 @@ SHAMap::getNodeFat( Serializer ns; childNode->addRaw(ns, snfWIRE); nodeIDs.push_back(childID); - rawNodes.push_back(std::move(ns.peekData())); + rawNodes.push_back(std::move(ns.modData())); } } } diff --git a/src/ripple/shamap/impl/SHAMapTreeNode.cpp b/src/ripple/shamap/impl/SHAMapTreeNode.cpp index 875e6326a0..cbf5a3745e 100644 --- a/src/ripple/shamap/impl/SHAMapTreeNode.cpp +++ b/src/ripple/shamap/impl/SHAMapTreeNode.cpp @@ -56,23 +56,23 @@ SHAMapTreeNode::clone(std::uint32_t seq) const } SHAMapTreeNode::SHAMapTreeNode( - std::shared_ptr const& item, + std::shared_ptr item, TNType type, std::uint32_t seq) - : SHAMapAbstractNode(type, seq), mItem(item) + : SHAMapAbstractNode(type, seq), mItem(std::move(item)) { - assert(item->peekData().size() >= 12); + assert(mItem->peekData().size() >= 12); updateHash(); } SHAMapTreeNode::SHAMapTreeNode( - std::shared_ptr const& item, + std::shared_ptr item, TNType type, std::uint32_t seq, SHAMapHash const& hash) - : SHAMapAbstractNode(type, seq, hash), mItem(item) + : SHAMapAbstractNode(type, seq, hash), mItem(std::move(item)) { - assert(item->peekData().size() >= 12); + assert(mItem->peekData().size() >= 12); } std::shared_ptr @@ -105,9 +105,9 @@ SHAMapAbstractNode::make( s.peekData()); if (hashValid) return std::make_shared( - item, tnTRANSACTION_NM, seq, hash); + std::move(item), tnTRANSACTION_NM, seq, hash); return std::make_shared( - item, tnTRANSACTION_NM, seq); + std::move(item), tnTRANSACTION_NM, seq); } else if (type == 1) { @@ -125,8 +125,9 @@ SHAMapAbstractNode::make( auto item = std::make_shared(u, s.peekData()); if (hashValid) return std::make_shared( - item, tnACCOUNT_STATE, seq, hash); - return std::make_shared(item, tnACCOUNT_STATE, seq); + std::move(item), tnACCOUNT_STATE, seq, hash); + return std::make_shared( + std::move(item), tnACCOUNT_STATE, seq); } else if (type == 2) { @@ -185,9 +186,9 @@ SHAMapAbstractNode::make( auto item = std::make_shared(u, s.peekData()); if (hashValid) return std::make_shared( - item, tnTRANSACTION_MD, seq, hash); + std::move(item), tnTRANSACTION_MD, seq, hash); return std::make_shared( - item, tnTRANSACTION_MD, seq); + std::move(item), tnTRANSACTION_MD, seq); } } @@ -214,9 +215,9 @@ SHAMapAbstractNode::make( sha512Half(rawNode), s.peekData()); if (hashValid) return std::make_shared( - item, tnTRANSACTION_NM, seq, hash); + std::move(item), tnTRANSACTION_NM, seq, hash); return std::make_shared( - item, tnTRANSACTION_NM, seq); + std::move(item), tnTRANSACTION_NM, seq); } else if (safe_cast(prefix) == HashPrefix::leafNode) { @@ -236,8 +237,9 @@ SHAMapAbstractNode::make( auto item = std::make_shared(u, s.peekData()); if (hashValid) return std::make_shared( - item, tnACCOUNT_STATE, seq, hash); - return std::make_shared(item, tnACCOUNT_STATE, seq); + std::move(item), tnACCOUNT_STATE, seq, hash); + return std::make_shared( + std::move(item), tnACCOUNT_STATE, seq); } else if (safe_cast(prefix) == HashPrefix::innerNode) { @@ -274,9 +276,9 @@ SHAMapAbstractNode::make( auto item = std::make_shared(txID, s.peekData()); if (hashValid) return std::make_shared( - item, tnTRANSACTION_MD, seq, hash); + std::move(item), tnTRANSACTION_MD, seq, hash); return std::make_shared( - item, tnTRANSACTION_MD, seq); + std::move(item), tnTRANSACTION_MD, seq); } else { @@ -459,10 +461,10 @@ SHAMapTreeNode::addRaw(Serializer& s, SHANodeFormat format) const } bool -SHAMapTreeNode::setItem(std::shared_ptr const& i, TNType type) +SHAMapTreeNode::setItem(std::shared_ptr i, TNType type) { mType = type; - mItem = i; + mItem = std::move(i); assert(isLeaf()); assert(mSeq != 0); return updateHash(); diff --git a/src/test/app/Manifest_test.cpp b/src/test/app/Manifest_test.cpp index f092e89f1b..063b438328 100644 --- a/src/test/app/Manifest_test.cpp +++ b/src/test/app/Manifest_test.cpp @@ -183,11 +183,13 @@ public: Serializer s; st.add(s); - std::string const m(static_cast(s.data()), s.size()); + // m is non-const so it can be moved from + std::string m(static_cast(s.data()), s.size()); if (auto r = deserializeManifest(std::move(m))) return std::move(*r); Throw("Could not create a revocation manifest"); - return *deserializeManifest(std::move(m)); // Silence compiler warning. + return *deserializeManifest( + std::string{}); // Silence compiler warning. } Manifest @@ -223,11 +225,14 @@ public: Serializer s; st.add(s); - std::string const m(static_cast(s.data()), s.size()); + std::string m( + static_cast(s.data()), + s.size()); // non-const so can be moved if (auto r = deserializeManifest(std::move(m))) return std::move(*r); Throw("Could not create a manifest"); - return *deserializeManifest(std::move(m)); // Silence compiler warning. + return *deserializeManifest( + std::string{}); // Silence compiler warning. } Manifest diff --git a/src/test/app/Regression_test.cpp b/src/test/app/Regression_test.cpp index 313506e31f..e7c4dc7d5b 100644 --- a/src/test/app/Regression_test.cpp +++ b/src/test/app/Regression_test.cpp @@ -146,7 +146,7 @@ struct Regression_test : public beast::unit_test::suite auto secp256r1Sig = std::make_unique(*(jt.stx)); auto pubKeyBlob = strUnHex(secp256r1PubKey); assert(pubKeyBlob); // Hex for public key must be valid - secp256r1Sig->setFieldVL(sfSigningPubKey, std::move(*pubKeyBlob)); + secp256r1Sig->setFieldVL(sfSigningPubKey, *pubKeyBlob); jt.stx.reset(secp256r1Sig.release()); env(jt, ter(temINVALID)); diff --git a/src/test/jtx/impl/Account.cpp b/src/test/jtx/impl/Account.cpp index 80d8f5e87e..3a3e095971 100644 --- a/src/test/jtx/impl/Account.cpp +++ b/src/test/jtx/impl/Account.cpp @@ -48,7 +48,7 @@ Account::Account( Account Account::fromCache(std::string name, KeyType type) { - auto const p = std::make_pair(name, type); + auto p = std::make_pair(name, type); // non-const so it can be moved from auto const iter = cache_.find(p); if (iter != cache_.end()) return iter->second; diff --git a/src/test/ledger/View_test.cpp b/src/test/ledger/View_test.cpp index e79bd17be7..3c462df280 100644 --- a/src/test/ledger/View_test.cpp +++ b/src/test/ledger/View_test.cpp @@ -151,7 +151,7 @@ class View_test : public beast::unit_test::suite BEAST_EXPECT(seq(v.read(k(3))) == 3); auto s = copy(v.read(k(2))); seq(s, 4); - ledger->rawReplace(std::move(s)); + ledger->rawReplace(s); BEAST_EXPECT(seq(v.read(k(2))) == 4); ledger->rawErase(sle(2)); BEAST_EXPECT(!v.exists(k(2)));