From 453d94da174ebe6691d835ffb63deefa06ee326b Mon Sep 17 00:00:00 2001 From: Alex Kremer Date: Mon, 30 Mar 2026 18:08:47 +0100 Subject: [PATCH] chore: Enable remaining clang-tidy `performance` checks (#6648) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .clang-tidy | 12 ++++----- include/xrpl/protocol/STVector256.h | 9 ------- include/xrpl/tx/transactors/dex/AMMHelpers.h | 9 +++---- src/libxrpl/basics/FileUtilities.cpp | 2 +- src/libxrpl/ledger/Ledger.cpp | 5 ++-- src/libxrpl/ledger/helpers/TokenHelpers.cpp | 2 +- src/libxrpl/protocol/BuildInfo.cpp | 2 +- src/libxrpl/protocol/STPathSet.cpp | 4 +-- src/libxrpl/shamap/SHAMap.cpp | 5 +--- .../PermissionedDomainInvariant.cpp | 2 +- src/libxrpl/tx/invariants/VaultInvariant.cpp | 4 +-- .../tx/transactors/bridge/XChainBridge.cpp | 2 +- .../tx/transactors/nft/NFTokenAcceptOffer.cpp | 2 +- .../tx/transactors/nft/NFTokenUtils.cpp | 2 +- .../tx/transactors/oracle/OracleSet.cpp | 4 +-- src/test/app/Batch_test.cpp | 1 + src/test/app/Invariants_test.cpp | 4 +-- src/test/app/LedgerReplay_test.cpp | 1 + src/test/app/Loan_test.cpp | 10 ++++--- src/test/app/Manifest_test.cpp | 11 ++++---- src/test/app/Offer_test.cpp | 6 ++--- src/test/app/RCLValidations_test.cpp | 2 +- src/test/app/Transaction_ordering_test.cpp | 10 ++++--- src/test/app/ValidatorList_test.cpp | 2 ++ src/test/app/ValidatorSite_test.cpp | 1 + src/test/app/Vault_test.cpp | 2 +- src/test/basics/IntrusiveShared_test.cpp | 3 +++ .../beast/aged_associative_container_test.cpp | 2 +- src/test/conditions/PreimageSha256_test.cpp | 2 +- src/test/consensus/Validations_test.cpp | 3 ++- src/test/jtx/TestHelpers.h | 2 +- src/test/jtx/impl/AMMTest.cpp | 2 +- src/test/jtx/impl/mpt.cpp | 4 +-- src/test/jtx/mpt.h | 2 +- src/test/jtx/multisign.h | 2 +- src/test/ledger/Directory_test.cpp | 2 +- src/test/protocol/MultiApiJson_test.cpp | 10 +++---- src/xrpld/app/consensus/RCLCxPeerPos.cpp | 4 +-- src/xrpld/app/consensus/RCLCxPeerPos.h | 2 +- src/xrpld/app/consensus/RCLValidations.cpp | 2 +- src/xrpld/app/ledger/detail/LedgerMaster.cpp | 2 +- src/xrpld/app/main/Application.cpp | 2 +- src/xrpld/app/main/GRPCServer.cpp | 6 ++--- src/xrpld/app/main/Main.cpp | 1 + src/xrpld/app/misc/NetworkOPs.cpp | 6 ++--- src/xrpld/app/misc/detail/ValidatorList.cpp | 6 ++--- src/xrpld/app/misc/detail/ValidatorSite.cpp | 13 +++++----- .../app/rdb/backend/detail/SQLiteDatabase.cpp | 26 ++++++++++--------- src/xrpld/overlay/detail/OverlayImpl.cpp | 4 +-- src/xrpld/overlay/detail/ProtocolMessage.h | 2 +- src/xrpld/peerfinder/detail/Logic.h | 4 +-- src/xrpld/rpc/detail/RPCCall.cpp | 10 ++++--- src/xrpld/rpc/detail/ServerHandler.cpp | 2 +- src/xrpld/rpc/handlers/AMMInfo.cpp | 2 +- src/xrpld/rpc/handlers/AccountChannels.cpp | 2 +- .../rpc/handlers/AccountCurrenciesHandler.cpp | 2 +- src/xrpld/rpc/handlers/AccountInfo.cpp | 2 +- src/xrpld/rpc/handlers/AccountLines.cpp | 2 +- src/xrpld/rpc/handlers/AccountOffers.cpp | 2 +- src/xrpld/rpc/handlers/AccountTx.cpp | 4 +-- src/xrpld/rpc/handlers/DepositAuthorized.cpp | 4 +-- src/xrpld/rpc/handlers/GatewayBalances.cpp | 4 +-- src/xrpld/rpc/handlers/LedgerEntry.cpp | 2 +- src/xrpld/rpc/handlers/LedgerEntryHelpers.h | 8 +++--- src/xrpld/rpc/handlers/NoRippleCheck.cpp | 2 +- src/xrpld/rpc/handlers/ServerDefinitions.cpp | 2 +- 66 files changed, 141 insertions(+), 139 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 449198eef8..36b59f43e3 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -97,8 +97,13 @@ Checks: "-*, modernize-deprecated-headers, modernize-make-shared, modernize-make-unique, + performance-faster-string-find, + performance-for-range-copy, performance-implicit-conversion-in-loop, + performance-inefficient-vector-operation, + performance-move-const-arg, performance-move-constructor-init, + performance-no-automatic-move, performance-trivially-destructible, # readability-avoid-nested-conditional-operator, # has issues # readability-avoid-return-with-void-value, # has issues @@ -150,13 +155,6 @@ Checks: "-*, # modernize-use-starts-ends-with, # modernize-use-std-numbers, # modernize-use-using, -# -# the following are in https://github.com/XRPLF/rippled/pull/6648 : -# performance-faster-string-find, -# performance-for-range-copy, -# performance-inefficient-vector-operation, -# performance-move-const-arg, -# performance-no-automatic-move, # --- # CheckOptions: diff --git a/include/xrpl/protocol/STVector256.h b/include/xrpl/protocol/STVector256.h index dd77067b7c..815224def2 100644 --- a/include/xrpl/protocol/STVector256.h +++ b/include/xrpl/protocol/STVector256.h @@ -69,9 +69,6 @@ public: std::vector::iterator insert(std::vector::const_iterator pos, uint256 const& value); - std::vector::iterator - insert(std::vector::const_iterator pos, uint256&& value); - void push_back(uint256 const& v); @@ -184,12 +181,6 @@ STVector256::insert(std::vector::const_iterator pos, uint256 const& val return mValue.insert(pos, value); } -inline std::vector::iterator -STVector256::insert(std::vector::const_iterator pos, uint256&& value) -{ - return mValue.insert(pos, std::move(value)); -} - inline void STVector256::push_back(uint256 const& v) { diff --git a/include/xrpl/tx/transactors/dex/AMMHelpers.h b/include/xrpl/tx/transactors/dex/AMMHelpers.h index e2735ea80f..6e3957769f 100644 --- a/include/xrpl/tx/transactors/dex/AMMHelpers.h +++ b/include/xrpl/tx/transactors/dex/AMMHelpers.h @@ -203,7 +203,7 @@ getAMMOfferStartWithTakerGets( // Try to reduce the offer size to improve the quality. // The quality might still not match the targetQuality for a tiny offer. - if (auto const amounts = getAmounts(*nTakerGets); Quality{amounts} < targetQuality) + if (auto amounts = getAmounts(*nTakerGets); Quality{amounts} < targetQuality) return getAmounts(detail::reduceOffer(amounts.out)); else return amounts; @@ -270,7 +270,7 @@ getAMMOfferStartWithTakerPays( // Try to reduce the offer size to improve the quality. // The quality might still not match the targetQuality for a tiny offer. - if (auto const amounts = getAmounts(*nTakerPays); Quality{amounts} < targetQuality) + if (auto amounts = getAmounts(*nTakerPays); Quality{amounts} < targetQuality) return getAmounts(detail::reduceOffer(amounts.in)); else return amounts; @@ -335,8 +335,7 @@ changeSpotPriceQuality( } auto const takerPays = toAmount(getIssue(pool.in), nTakerPays, Number::upward); // should not fail - if (auto const amounts = - TAmounts{takerPays, swapAssetIn(pool, takerPays, tfee)}; + if (auto amounts = TAmounts{takerPays, swapAssetIn(pool, takerPays, tfee)}; Quality{amounts} < quality && !withinRelativeDistance(Quality{amounts}, quality, Number(1, -7))) { @@ -362,7 +361,7 @@ changeSpotPriceQuality( // Generate the offer starting with XRP side. Return seated offer amounts // if the offer can be generated, otherwise nullopt. - auto const amounts = [&]() { + auto amounts = [&]() { if (isXRP(getIssue(pool.out))) return getAMMOfferStartWithTakerGets(pool, quality, tfee); return getAMMOfferStartWithTakerPays(pool, quality, tfee); diff --git a/src/libxrpl/basics/FileUtilities.cpp b/src/libxrpl/basics/FileUtilities.cpp index 0f636276da..73f2c2f10d 100644 --- a/src/libxrpl/basics/FileUtilities.cpp +++ b/src/libxrpl/basics/FileUtilities.cpp @@ -45,7 +45,7 @@ getFileContents( return {}; } - std::string const result{ + std::string result{ std::istreambuf_iterator{fileStream}, std::istreambuf_iterator{}}; if (fileStream.bad()) diff --git a/src/libxrpl/ledger/Ledger.cpp b/src/libxrpl/ledger/Ledger.cpp index 47009d198a..87f6350ce1 100644 --- a/src/libxrpl/ledger/Ledger.cpp +++ b/src/libxrpl/ledger/Ledger.cpp @@ -80,8 +80,7 @@ public: txs_iter_impl(txs_iter_impl const&) = default; - txs_iter_impl(bool metadata, SHAMap::const_iterator iter) - : metadata_(metadata), iter_(std::move(iter)) + txs_iter_impl(bool metadata, SHAMap::const_iterator iter) : metadata_(metadata), iter_(iter) { } @@ -694,7 +693,7 @@ Ledger::updateNegativeUNL() if (sle->isFieldPresent(sfDisabledValidators)) { auto const& oldNUnl = sle->getFieldArray(sfDisabledValidators); - for (auto v : oldNUnl) + for (auto const& v : oldNUnl) { if (hasToReEnable && v.isFieldPresent(sfPublicKey) && v.getFieldVL(sfPublicKey) == sle->getFieldVL(sfValidatorToReEnable)) diff --git a/src/libxrpl/ledger/helpers/TokenHelpers.cpp b/src/libxrpl/ledger/helpers/TokenHelpers.cpp index 9eb1b4bf11..27ee257e64 100644 --- a/src/libxrpl/ledger/helpers/TokenHelpers.cpp +++ b/src/libxrpl/ledger/helpers/TokenHelpers.cpp @@ -161,7 +161,7 @@ getLineIfUsable( FreezeHandling zeroIfFrozen, beast::Journal j) { - auto const sle = view.read(keylet::line(account, issuer, currency)); + auto sle = view.read(keylet::line(account, issuer, currency)); if (!sle) { diff --git a/src/libxrpl/protocol/BuildInfo.cpp b/src/libxrpl/protocol/BuildInfo.cpp index 2ccc5088e2..15b1f30082 100644 --- a/src/libxrpl/protocol/BuildInfo.cpp +++ b/src/libxrpl/protocol/BuildInfo.cpp @@ -113,7 +113,7 @@ encodeSoftwareVersion(std::string_view versionStr) { std::uint8_t x = 0; - for (auto id : v.preReleaseIdentifiers) + for (auto const& id : v.preReleaseIdentifiers) { auto parsePreRelease = [](std::string_view identifier, std::string_view prefix, diff --git a/src/libxrpl/protocol/STPathSet.cpp b/src/libxrpl/protocol/STPathSet.cpp index 86e61e91bf..fde33fb58e 100644 --- a/src/libxrpl/protocol/STPathSet.cpp +++ b/src/libxrpl/protocol/STPathSet.cpp @@ -153,7 +153,7 @@ STPath::getJson(JsonOptions) const { Json::Value ret(Json::arrayValue); - for (auto it : mPath) + for (auto const& it : mPath) { Json::Value elem(Json::objectValue); auto const iType = it.getNodeType(); @@ -179,7 +179,7 @@ Json::Value STPathSet::getJson(JsonOptions options) const { Json::Value ret(Json::arrayValue); - for (auto it : value) + for (auto const& it : value) ret.append(it.getJson(options)); return ret; diff --git a/src/libxrpl/shamap/SHAMap.cpp b/src/libxrpl/shamap/SHAMap.cpp index a9182a59cf..8a853e4d1b 100644 --- a/src/libxrpl/shamap/SHAMap.cpp +++ b/src/libxrpl/shamap/SHAMap.cpp @@ -1021,10 +1021,7 @@ SHAMap::walkSubTree(bool doWrite, NodeObjectType t) // 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 = intr_ptr::static_pointer_cast(std::move(child)); + node = intr_ptr::static_pointer_cast(child); pos = 0; } else diff --git a/src/libxrpl/tx/invariants/PermissionedDomainInvariant.cpp b/src/libxrpl/tx/invariants/PermissionedDomainInvariant.cpp index 02eaee0552..7365fc7b1a 100644 --- a/src/libxrpl/tx/invariants/PermissionedDomainInvariant.cpp +++ b/src/libxrpl/tx/invariants/PermissionedDomainInvariant.cpp @@ -38,7 +38,7 @@ ValidPermissionedDomain::visitEntry( break; } } - sleStatus.emplace_back(std::move(ss)); + sleStatus.emplace_back(ss); }; if (after) diff --git a/src/libxrpl/tx/invariants/VaultInvariant.cpp b/src/libxrpl/tx/invariants/VaultInvariant.cpp index f0dd82c2f8..c6b3295569 100644 --- a/src/libxrpl/tx/invariants/VaultInvariant.cpp +++ b/src/libxrpl/tx/invariants/VaultInvariant.cpp @@ -205,7 +205,7 @@ ValidVault::finalize( for (auto const& e : beforeMPTs_) { if (e.share.getMptID() == beforeVault.shareMPTID) - return std::move(e); + return e; } return std::nullopt; }(); @@ -374,7 +374,7 @@ ValidVault::finalize( for (auto const& e : beforeMPTs_) { if (e.share.getMptID() == beforeVault.shareMPTID) - return std::move(e); + return e; } return std::nullopt; }(); diff --git a/src/libxrpl/tx/transactors/bridge/XChainBridge.cpp b/src/libxrpl/tx/transactors/bridge/XChainBridge.cpp index 8c09fefe5a..f0e57919d9 100644 --- a/src/libxrpl/tx/transactors/bridge/XChainBridge.cpp +++ b/src/libxrpl/tx/transactors/bridge/XChainBridge.cpp @@ -418,7 +418,7 @@ transferHelper( auto const reserve = psb.fees().accountReserve(ownerCount); auto const availableBalance = [&]() -> STAmount { - STAmount const curBal = (*sleSrc)[sfBalance]; + STAmount curBal = (*sleSrc)[sfBalance]; // Checking that account == src and postFeeBalance == curBal is // not strictly necessary, but helps protect against future // changes diff --git a/src/libxrpl/tx/transactors/nft/NFTokenAcceptOffer.cpp b/src/libxrpl/tx/transactors/nft/NFTokenAcceptOffer.cpp index 15a745b8dd..e061dbe7ec 100644 --- a/src/libxrpl/tx/transactors/nft/NFTokenAcceptOffer.cpp +++ b/src/libxrpl/tx/transactors/nft/NFTokenAcceptOffer.cpp @@ -344,7 +344,7 @@ NFTokenAcceptOffer::transferNFToken( if (!tokenAndPage) return tecINTERNAL; // LCOV_EXCL_LINE - if (auto const ret = nft::removeToken(view(), seller, nftokenID, std::move(tokenAndPage->page)); + if (auto const ret = nft::removeToken(view(), seller, nftokenID, tokenAndPage->page); !isTesSuccess(ret)) return ret; diff --git a/src/libxrpl/tx/transactors/nft/NFTokenUtils.cpp b/src/libxrpl/tx/transactors/nft/NFTokenUtils.cpp index 84826314e7..6a8b830bf0 100644 --- a/src/libxrpl/tx/transactors/nft/NFTokenUtils.cpp +++ b/src/libxrpl/tx/transactors/nft/NFTokenUtils.cpp @@ -344,7 +344,7 @@ removeToken(ApplyView& view, AccountID const& owner, uint256 const& nftokenID) if (!page) return tecNO_ENTRY; - return removeToken(view, owner, nftokenID, std::move(page)); + return removeToken(view, owner, nftokenID, page); } /** Remove the token from the owner's token directory. */ diff --git a/src/libxrpl/tx/transactors/oracle/OracleSet.cpp b/src/libxrpl/tx/transactors/oracle/OracleSet.cpp index 061dd16b0c..772756ad6d 100644 --- a/src/libxrpl/tx/transactors/oracle/OracleSet.cpp +++ b/src/libxrpl/tx/transactors/oracle/OracleSet.cpp @@ -236,7 +236,7 @@ OracleSet::doApply() } STArray updatedSeries; for (auto const& iter : pairs) - updatedSeries.push_back(std::move(iter.second)); + updatedSeries.push_back(iter.second); sle->setFieldArray(sfPriceDataSeries, updatedSeries); if (ctx_.tx.isFieldPresent(sfURI)) sle->setFieldVL(sfURI, ctx_.tx[sfURI]); @@ -284,7 +284,7 @@ OracleSet::doApply() pairs.emplace(key, std::move(priceData)); } for (auto const& iter : pairs) - series.push_back(std::move(iter.second)); + series.push_back(iter.second); } sle->setFieldArray(sfPriceDataSeries, series); diff --git a/src/test/app/Batch_test.cpp b/src/test/app/Batch_test.cpp index adc36e4340..a548eb6b49 100644 --- a/src/test/app/Batch_test.cpp +++ b/src/test/app/Batch_test.cpp @@ -93,6 +93,7 @@ class Batch_test : public beast::unit_test::suite auto const ids = batchTxn.stx->getBatchTransactionIDs(); std::vector txIDs; + txIDs.reserve(ids.size()); for (auto const& id : ids) txIDs.push_back(strHex(id)); TxID const batchID = batchTxn.stx->getTransactionID(); diff --git a/src/test/app/Invariants_test.cpp b/src/test/app/Invariants_test.cpp index 9653a36edf..ca63a69bc4 100644 --- a/src/test/app/Invariants_test.cpp +++ b/src/test/app/Invariants_test.cpp @@ -1193,7 +1193,7 @@ class Invariants_test : public beast::unit_test::suite STArray nfTokens = makeNFTokenIDs(1); auto nftPage = std::make_shared(keylet::nftpage( keylet::nftpage_max(A1), ++(nfTokens[0].getFieldH256(sfNFTokenID)))); - nftPage->setFieldArray(sfNFTokens, std::move(nfTokens)); + nftPage->setFieldArray(sfNFTokens, nfTokens); nftPage->setFieldH256(sfNextPageMin, keylet::nftpage_max(A2).key); ac.view().insert(nftPage); @@ -1206,7 +1206,7 @@ class Invariants_test : public beast::unit_test::suite STArray nfTokens = makeNFTokenIDs(2); auto nftPage = std::make_shared(keylet::nftpage( keylet::nftpage_max(A1), (nfTokens[1].getFieldH256(sfNFTokenID)))); - nftPage->setFieldArray(sfNFTokens, std::move(nfTokens)); + nftPage->setFieldArray(sfNFTokens, nfTokens); ac.view().insert(nftPage); return true; diff --git a/src/test/app/LedgerReplay_test.cpp b/src/test/app/LedgerReplay_test.cpp index cc7cfa413c..93811d33b0 100644 --- a/src/test/app/LedgerReplay_test.cpp +++ b/src/test/app/LedgerReplay_test.cpp @@ -968,6 +968,7 @@ struct LedgerReplayer_test : public beast::unit_test::suite auto makeSkipList = [](int count) -> std::vector { std::vector sList; + sList.reserve(count); for (int i = 0; i < count; ++i) sList.emplace_back(i); return sList; diff --git a/src/test/app/Loan_test.cpp b/src/test/app/Loan_test.cpp index fa7befd39e..4cdc62853c 100644 --- a/src/test/app/Loan_test.cpp +++ b/src/test/app/Loan_test.cpp @@ -1539,7 +1539,7 @@ protected: auto const pseudoAcct = [&]() { auto const brokerSle = env.le(keylet::loanbroker(broker.brokerID)); if (!BEAST_EXPECT(brokerSle)) - return lender; + return Account{lender}; auto const brokerPseudo = brokerSle->at(sfAccount); return Account("Broker pseudo-account", brokerPseudo); }(); @@ -1809,9 +1809,9 @@ protected: if (!BEAST_EXPECT(vaultSle)) { // This will be wrong, but the test has failed anyway. - return lender; + return Account{lender}; } - auto const vaultPseudo = Account("Vault pseudo-account", vaultSle->at(sfAccount)); + auto vaultPseudo = Account("Vault pseudo-account", vaultSle->at(sfAccount)); return vaultPseudo; }(); @@ -2875,6 +2875,7 @@ protected: // Create vaults and loan brokers std::array const assets{mptAsset, iouAsset}; std::vector brokers; + brokers.reserve(assets.size()); for (auto const& asset : assets) { brokers.emplace_back(createVaultAndBroker(env, asset, lender)); @@ -3408,6 +3409,7 @@ protected: // Create vaults and loan brokers std::vector brokers; + brokers.reserve(assets.size()); for (auto const& asset : assets) { brokers.emplace_back(createVaultAndBroker( @@ -4566,7 +4568,7 @@ protected: auto const pseudoAcct = [&]() { auto const brokerSle = env.le(keylet::loanbroker(broker.brokerID)); if (!BEAST_EXPECT(brokerSle)) - return lender; + return Account{lender}; auto const brokerPseudo = brokerSle->at(sfAccount); return Account("Broker pseudo-account", brokerPseudo); }(); diff --git a/src/test/app/Manifest_test.cpp b/src/test/app/Manifest_test.cpp index 7039f8df4f..92a10ef7fa 100644 --- a/src/test/app/Manifest_test.cpp +++ b/src/test/app/Manifest_test.cpp @@ -147,9 +147,8 @@ public: Serializer s; st.add(s); - // 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))) + std::string const m(static_cast(s.data()), s.size()); + if (auto r = deserializeManifest(m)) return std::move(*r); Throw("Could not create a revocation manifest"); return *deserializeManifest(std::string{}); // Silence compiler warning. @@ -182,9 +181,8 @@ public: Serializer s; st.add(s); - std::string m(static_cast(s.data()), - s.size()); // non-const so can be moved - if (auto r = deserializeManifest(std::move(m))) + std::string const m(static_cast(s.data()), s.size()); + if (auto r = deserializeManifest(m)) return std::move(*r); Throw("Could not create a manifest"); return *deserializeManifest(std::string{}); // Silence compiler warning. @@ -252,6 +250,7 @@ public: // save should store all trusted master keys to db std::vector s1; std::vector keys; + s1.reserve(inManifests.size()); for (auto const& man : inManifests) s1.push_back(toBase58(TokenType::NodePublic, man->masterKey)); unl->load({}, s1, keys); diff --git a/src/test/app/Offer_test.cpp b/src/test/app/Offer_test.cpp index 35146f5234..57f938e399 100644 --- a/src/test/app/Offer_test.cpp +++ b/src/test/app/Offer_test.cpp @@ -863,7 +863,7 @@ public: auto const aliceOffers = offersOnAccount(env, alice); BEAST_EXPECT(aliceOffers.size() == 1); - for (auto offerPtr : aliceOffers) + for (auto const& offerPtr : aliceOffers) { auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfTakerGets] == XRP(2000)); @@ -878,7 +878,7 @@ public: auto const bobOffers = offersOnAccount(env, bob); BEAST_EXPECT(bobOffers.size() == 1); - for (auto offerPtr : bobOffers) + for (auto const& offerPtr : bobOffers) { auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfTakerGets] == USD(1000)); @@ -927,7 +927,7 @@ public: auto const bobOffers = offersOnAccount(env, "bob"); BEAST_EXPECT(bobOffers.size() == 1); - for (auto offerPtr : bobOffers) + for (auto const& offerPtr : bobOffers) { auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfTakerGets] == USD(499.5)); diff --git a/src/test/app/RCLValidations_test.cpp b/src/test/app/RCLValidations_test.cpp index e15569102a..537563ecc4 100644 --- a/src/test/app/RCLValidations_test.cpp +++ b/src/test/app/RCLValidations_test.cpp @@ -132,7 +132,7 @@ class RCLValidations_test : public beast::unit_test::suite { RCLValidatedLedger a{RCLValidatedLedger::MakeGenesis{}}; - for (auto ledger : {history.back(), history[maxAncestors - 1]}) + for (auto const& ledger : {history.back(), history[maxAncestors - 1]}) { RCLValidatedLedger b{ledger, env.journal}; BEAST_EXPECT(mismatch(a, b) == 1); diff --git a/src/test/app/Transaction_ordering_test.cpp b/src/test/app/Transaction_ordering_test.cpp index f7d431fc90..c50fbf4e56 100644 --- a/src/test/app/Transaction_ordering_test.cpp +++ b/src/test/app/Transaction_ordering_test.cpp @@ -95,14 +95,16 @@ struct Transaction_ordering_test : public beast::unit_test::suite env.fund(XRP(1000), noripple(alice)); auto const aliceSequence = env.seq(alice); + static constexpr auto kSIZE = 5; std::vector tx; - for (auto i = 0; i < 5; ++i) + tx.reserve(kSIZE); + for (auto i = 0; i < kSIZE; ++i) { tx.emplace_back(env.jt(noop(alice), seq(aliceSequence + i), last_ledger_seq(7))); } - for (auto i = 1; i < 5; ++i) + for (auto i = 1; i < kSIZE; ++i) { env(tx[i], ter(terPRE_SEQ)); BEAST_EXPECT(env.seq(alice) == aliceSequence); @@ -110,11 +112,11 @@ struct Transaction_ordering_test : public beast::unit_test::suite env(tx[0]); env.app().getJobQueue().rendezvous(); - BEAST_EXPECT(env.seq(alice) == aliceSequence + 5); + BEAST_EXPECT(env.seq(alice) == aliceSequence + kSIZE); env.close(); - for (auto i = 0; i < 5; ++i) + for (auto i = 0; i < kSIZE; ++i) { auto const result = env.rpc("tx", to_string(tx[i].stx->getTransactionID())); BEAST_EXPECT(result["result"]["meta"]["TransactionResult"] == "tesSUCCESS"); diff --git a/src/test/app/ValidatorList_test.cpp b/src/test/app/ValidatorList_test.cpp index 10e34cacad..3f1c20ee25 100644 --- a/src/test/app/ValidatorList_test.cpp +++ b/src/test/app/ValidatorList_test.cpp @@ -373,6 +373,7 @@ private: // load should accept valid validator list publisher keys std::vector cfgPublishers; + cfgPublishers.reserve(keys.size()); for (auto const& key : keys) cfgPublishers.push_back(strHex(key)); @@ -393,6 +394,7 @@ private: std::vector keys( {randomMasterKey(), randomMasterKey(), randomMasterKey(), randomMasterKey()}); std::vector cfgPublishers; + cfgPublishers.reserve(keys.size()); for (auto const& key : keys) cfgPublishers.push_back(strHex(key)); diff --git a/src/test/app/ValidatorSite_test.cpp b/src/test/app/ValidatorSite_test.cpp index 160da452ee..ee28410d9e 100644 --- a/src/test/app/ValidatorSite_test.cpp +++ b/src/test/app/ValidatorSite_test.cpp @@ -298,6 +298,7 @@ private: auto sites = std::make_unique(env.app(), journal); std::vector uris; + uris.reserve(servers.size()); for (auto const& u : servers) uris.push_back(u.uri); sites->load(uris); diff --git a/src/test/app/Vault_test.cpp b/src/test/app/Vault_test.cpp index 37ad3ae334..54cc6646b1 100644 --- a/src/test/app/Vault_test.cpp +++ b/src/test/app/Vault_test.cpp @@ -1329,7 +1329,7 @@ class Vault_test : public beast::unit_test::suite return defXRP; return a + XRP(1000); } - auto const defIOU = STAmount{a.issue(), 30000}; + auto defIOU = STAmount{a.issue(), 30000}; if (a <= defIOU) return defIOU; return a + STAmount{a.issue(), 1000}; diff --git a/src/test/basics/IntrusiveShared_test.cpp b/src/test/basics/IntrusiveShared_test.cpp index 5a460a6044..41ecf9a7a4 100644 --- a/src/test/basics/IntrusiveShared_test.cpp +++ b/src/test/basics/IntrusiveShared_test.cpp @@ -592,6 +592,7 @@ public: } }; std::vector threads; + threads.reserve(numThreads); for (int i = 0; i < numThreads; ++i) { threads.emplace_back(cloneAndDestroy, i); @@ -737,6 +738,7 @@ public: } }; std::vector threads; + threads.reserve(numThreads); for (int i = 0; i < numThreads; ++i) { threads.emplace_back(cloneAndDestroy, i); @@ -845,6 +847,7 @@ public: } }; std::vector threads; + threads.reserve(numThreads); for (int i = 0; i < numThreads; ++i) { threads.emplace_back(lockAndDestroy, i); diff --git a/src/test/beast/aged_associative_container_test.cpp b/src/test/beast/aged_associative_container_test.cpp index 22b677a7e5..1578ffceca 100644 --- a/src/test/beast/aged_associative_container_test.cpp +++ b/src/test/beast/aged_associative_container_test.cpp @@ -1362,7 +1362,7 @@ aged_associative_container_test_base::testArrayCreate() { // Copy construct key typename Traits::template Cont<> c(clock); - for (auto e : v) + for (auto const& e : v) c[e.first] = e.second; checkContents(c, v); } diff --git a/src/test/conditions/PreimageSha256_test.cpp b/src/test/conditions/PreimageSha256_test.cpp index 973f714ba4..374b6eb925 100644 --- a/src/test/conditions/PreimageSha256_test.cpp +++ b/src/test/conditions/PreimageSha256_test.cpp @@ -149,7 +149,7 @@ class PreimageSha256_test : public beast::unit_test::suite "9CF1D5F810302" "0000"}}; - for (auto x : others) + for (auto const& x : others) { std::error_code ec; diff --git a/src/test/consensus/Validations_test.cpp b/src/test/consensus/Validations_test.cpp index cf4498bd52..dc6dfe539c 100644 --- a/src/test/consensus/Validations_test.cpp +++ b/src/test/consensus/Validations_test.cpp @@ -373,7 +373,7 @@ class Validations_test : public beast::unit_test::suite [&](TestValidations& vals) { vals.getCurrentNodeIDs(); }, [&](TestValidations& vals) { vals.getPreferred(genesisLedger); }, [&](TestValidations& vals) { vals.getNodesAfter(ledgerA, ledgerA.id()); }}; - for (Trigger trigger : triggers) + for (Trigger const& trigger : triggers) { TestHarness harness(h.oracle); Node n = harness.makeNode(); @@ -569,6 +569,7 @@ class Validations_test : public beast::unit_test::suite std::uint32_t baseFee = 0; std::vector expectedFees; + expectedFees.reserve(expectedValidations.size()); for (auto const& val : expectedValidations) { expectedFees.push_back(val.loadFee().value_or(baseFee)); diff --git a/src/test/jtx/TestHelpers.h b/src/test/jtx/TestHelpers.h index 2836748ec3..08e86b40ac 100644 --- a/src/test/jtx/TestHelpers.h +++ b/src/test/jtx/TestHelpers.h @@ -317,7 +317,7 @@ template Json::Value getAccountLines(Env& env, AccountID const& acctId, IOU... ious) { - auto const jrr = getAccountLines(env, acctId); + auto jrr = getAccountLines(env, acctId); Json::Value res; for (auto const& line : jrr[jss::lines]) { diff --git a/src/test/jtx/impl/AMMTest.cpp b/src/test/jtx/impl/AMMTest.cpp index 6b8807076a..9d9a537210 100644 --- a/src/test/jtx/impl/AMMTest.cpp +++ b/src/test/jtx/impl/AMMTest.cpp @@ -119,7 +119,7 @@ AMMTestBase::testAMM(std::function const& cb, TestAM return defXRP; return a + XRP(1000); } - auto const defIOU = STAmount{a.issue(), 30000}; + auto defIOU = STAmount{a.issue(), 30000}; if (a <= defIOU) return defIOU; return a + STAmount{a.issue(), 1000}; diff --git a/src/test/jtx/impl/mpt.cpp b/src/test/jtx/impl/mpt.cpp index 933aabce30..2b78777838 100644 --- a/src/test/jtx/impl/mpt.cpp +++ b/src/test/jtx/impl/mpt.cpp @@ -45,7 +45,7 @@ MPTTester::MPTTester(Env& env, Account const& issuer, MPTInit const& arg) if (arg.fund) { env_.fund(arg.xrp, issuer_); - for (auto it : holders_) + for (auto const& it : holders_) env_.fund(arg.xrpHolders, it.second); } if (close_) @@ -53,7 +53,7 @@ MPTTester::MPTTester(Env& env, Account const& issuer, MPTInit const& arg) if (arg.fund) { env_.require(owners(issuer_, 0)); - for (auto it : holders_) + for (auto const& it : holders_) { if (issuer_.id() == it.second.id()) Throw("Issuer can't be holder"); diff --git a/src/test/jtx/mpt.h b/src/test/jtx/mpt.h index 3368d129c1..3990dd3087 100644 --- a/src/test/jtx/mpt.h +++ b/src/test/jtx/mpt.h @@ -291,7 +291,7 @@ private: env_.require(owners(issuer_, *arg.ownerCount)); if (arg.holderCount) { - for (auto it : holders_) + for (auto const& it : holders_) env_.require(owners(it.second, *arg.holderCount)); } return err; diff --git a/src/test/jtx/multisign.h b/src/test/jtx/multisign.h index 56d0b10906..b3f38cc453 100644 --- a/src/test/jtx/multisign.h +++ b/src/test/jtx/multisign.h @@ -22,7 +22,7 @@ struct signer std::optional tag; signer(Account account_, std::uint32_t weight_ = 1, std::optional tag_ = std::nullopt) - : weight(weight_), account(std::move(account_)), tag(std::move(tag_)) + : weight(weight_), account(std::move(account_)), tag(tag_) { } }; diff --git a/src/test/ledger/Directory_test.cpp b/src/test/ledger/Directory_test.cpp index b08e7daaf6..aec472fc6f 100644 --- a/src/test/ledger/Directory_test.cpp +++ b/src/test/ledger/Directory_test.cpp @@ -204,7 +204,7 @@ struct Directory_test : public beast::unit_test::suite BEAST_EXPECT(dirIsEmpty(*env.closed(), keylet::ownerDir(alice))); - for (auto c : currencies) + for (auto const& c : currencies) { env(trust(charlie, c(50))); env.close(); diff --git a/src/test/protocol/MultiApiJson_test.cpp b/src/test/protocol/MultiApiJson_test.cpp index 0da511b976..5aafa19771 100644 --- a/src/test/protocol/MultiApiJson_test.cpp +++ b/src/test/protocol/MultiApiJson_test.cpp @@ -236,7 +236,7 @@ struct MultiApiJson_test : beast::unit_test::suite std::forward(v).visit(), // [](auto...) {}); }; - }(std::move(std::as_const(s1)))); + }(std::move(std::as_const(s1)))); // NOLINT(performance-move-const-arg) } { @@ -867,22 +867,22 @@ struct MultiApiJson_test : beast::unit_test::suite return !requires { std::forward(v).visit(1, [](Json::Value const&&) {}); }; - }(std::move(std::as_const(s1)))); + }(std::move(std::as_const(s1)))); // NOLINT(performance-move-const-arg) static_assert([](auto&& v) { return requires { std::forward(v).visit(1, [](Json::Value const&) {}); }; - }(std::move(std::as_const(s1)))); + }(std::move(std::as_const(s1)))); // NOLINT(performance-move-const-arg) static_assert([](auto&& v) { return !requires { std::forward(v).visit()(1, [](Json::Value const&&) {}); }; - }(std::move(std::as_const(s1)))); + }(std::move(std::as_const(s1)))); // NOLINT(performance-move-const-arg) static_assert([](auto&& v) { return requires { std::forward(v).visit()(1, [](Json::Value const&) {}); }; - }(std::move(std::as_const(s1)))); + }(std::move(std::as_const(s1)))); // NOLINT(performance-move-const-arg) // Missing const static_assert([](auto&& v) { diff --git a/src/xrpld/app/consensus/RCLCxPeerPos.cpp b/src/xrpld/app/consensus/RCLCxPeerPos.cpp index 18a660fcd0..8f99dceea8 100644 --- a/src/xrpld/app/consensus/RCLCxPeerPos.cpp +++ b/src/xrpld/app/consensus/RCLCxPeerPos.cpp @@ -10,8 +10,8 @@ RCLCxPeerPos::RCLCxPeerPos( PublicKey const& publicKey, Slice const& signature, uint256 const& suppression, - Proposal&& proposal) - : publicKey_(publicKey), suppression_(suppression), proposal_(std::move(proposal)) + Proposal const& proposal) // trivially copyable + : publicKey_(publicKey), suppression_(suppression), proposal_(proposal) { // The maximum allowed size of a signature is 72 bytes; we verify // this elsewhere, but we want to be extra careful here: diff --git a/src/xrpld/app/consensus/RCLCxPeerPos.h b/src/xrpld/app/consensus/RCLCxPeerPos.h index 5dad4a33eb..e334320826 100644 --- a/src/xrpld/app/consensus/RCLCxPeerPos.h +++ b/src/xrpld/app/consensus/RCLCxPeerPos.h @@ -40,7 +40,7 @@ public: PublicKey const& publicKey, Slice const& signature, uint256 const& suppress, - Proposal&& proposal); + Proposal const& proposal); // trivially copyable //! Verify the signing hash of the proposal bool diff --git a/src/xrpld/app/consensus/RCLValidations.cpp b/src/xrpld/app/consensus/RCLValidations.cpp index 27fba69bb6..7bc16f194e 100644 --- a/src/xrpld/app/consensus/RCLValidations.cpp +++ b/src/xrpld/app/consensus/RCLValidations.cpp @@ -131,7 +131,7 @@ RCLValidationsAdaptor::acquire(LedgerHash const& hash) XRPL_ASSERT( ledger->header().hash == hash, "xrpl::RCLValidationsAdaptor::acquire : ledger hash match"); - return RCLValidatedLedger(std::move(ledger), j_); + return RCLValidatedLedger(ledger, j_); } void diff --git a/src/xrpld/app/ledger/detail/LedgerMaster.cpp b/src/xrpld/app/ledger/detail/LedgerMaster.cpp index 52ccd27ba4..6253b33da3 100644 --- a/src/xrpld/app/ledger/detail/LedgerMaster.cpp +++ b/src/xrpld/app/ledger/detail/LedgerMaster.cpp @@ -410,7 +410,7 @@ LedgerMaster::storeLedger(std::shared_ptr ledger) { bool validated = ledger->header().validated; // Returns true if we already had the ledger - return mLedgerHistory.insert(std::move(ledger), validated); + return mLedgerHistory.insert(ledger, validated); } /** Apply held transactions to the open ledger diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index 76a95bd542..0d8325be54 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -1411,7 +1411,7 @@ ApplicationImp::setup(boost::program_options::variables_map const& cmdline) // // Execute start up rpc commands. // - for (auto cmd : config_->section(SECTION_RPC_STARTUP).lines()) + for (auto const& cmd : config_->section(SECTION_RPC_STARTUP).lines()) { Json::Reader jrReader; Json::Value jvCommand; diff --git a/src/xrpld/app/main/GRPCServer.cpp b/src/xrpld/app/main/GRPCServer.cpp index f95c20ba8c..130d0f01b9 100644 --- a/src/xrpld/app/main/GRPCServer.cpp +++ b/src/xrpld/app/main/GRPCServer.cpp @@ -16,8 +16,8 @@ getEndpoint(std::string const& peer) { try { - std::size_t first = peer.find_first_of(":"); - std::size_t last = peer.find_last_of(":"); + std::size_t first = peer.find_first_of(':'); + std::size_t last = peer.find_last_of(':'); std::string peerClean(peer); if (first != last) { @@ -56,7 +56,7 @@ GRPCServerImpl::CallData::CallData( , bindListener_(std::move(bindListener)) , handler_(std::move(handler)) , forward_(std::move(forward)) - , requiredCondition_(std::move(requiredCondition)) + , requiredCondition_(requiredCondition) , loadType_(std::move(loadType)) , secureGatewayIPs_(secureGatewayIPs) { diff --git a/src/xrpld/app/main/Main.cpp b/src/xrpld/app/main/Main.cpp index 85f6ae651a..570131b52d 100644 --- a/src/xrpld/app/main/Main.cpp +++ b/src/xrpld/app/main/Main.cpp @@ -282,6 +282,7 @@ runUnitTests( args.emplace_back("--unittest-child"); } + children.reserve(num_jobs); for (std::size_t i = 0; i < num_jobs; ++i) { children.emplace_back( diff --git a/src/xrpld/app/misc/NetworkOPs.cpp b/src/xrpld/app/misc/NetworkOPs.cpp index ffccf765f0..b323541362 100644 --- a/src/xrpld/app/misc/NetworkOPs.cpp +++ b/src/xrpld/app/misc/NetworkOPs.cpp @@ -189,7 +189,7 @@ class NetworkOPsImp final : public NetworkOPs ServerFeeSummary( XRPAmount fee, - TxQ::Metrics&& escalationMetrics, + TxQ::Metrics escalationMetrics, // trivially copyable LoadFeeTrack const& loadFeeTrack); bool operator!=(ServerFeeSummary const& b) const; @@ -2142,12 +2142,12 @@ NetworkOPsImp::pubManifest(Manifest const& mo) NetworkOPsImp::ServerFeeSummary::ServerFeeSummary( XRPAmount fee, - TxQ::Metrics&& escalationMetrics, + TxQ::Metrics escalationMetrics, // trivially copyable LoadFeeTrack const& loadFeeTrack) : loadFactorServer{loadFeeTrack.getLoadFactor()} , loadBaseServer{loadFeeTrack.getLoadBase()} , baseFee{fee} - , em{std::move(escalationMetrics)} + , em{escalationMetrics} { } diff --git a/src/xrpld/app/misc/detail/ValidatorList.cpp b/src/xrpld/app/misc/detail/ValidatorList.cpp index 29c0e75c78..abf64a4a93 100644 --- a/src/xrpld/app/misc/detail/ValidatorList.cpp +++ b/src/xrpld/app/misc/detail/ValidatorList.cpp @@ -137,7 +137,7 @@ ValidatorList::load( JLOG(j_.debug()) << "Loading configured trusted validator list publisher keys"; std::size_t count = 0; - for (auto key : publisherKeys) + for (auto const& key : publisherKeys) { JLOG(j_.trace()) << "Processing '" << key << "'"; @@ -1406,7 +1406,7 @@ ValidatorList::getListedKey(PublicKey const& identity) const { std::shared_lock read_lock{mutex_}; - auto const pubKey = validatorManifests_.getMasterKey(identity); + auto pubKey = validatorManifests_.getMasterKey(identity); if (keyListings_.contains(pubKey)) return pubKey; return std::nullopt; @@ -1415,7 +1415,7 @@ ValidatorList::getListedKey(PublicKey const& identity) const std::optional ValidatorList::getTrustedKey(ValidatorList::shared_lock const&, PublicKey const& identity) const { - auto const pubKey = validatorManifests_.getMasterKey(identity); + auto pubKey = validatorManifests_.getMasterKey(identity); if (trustedMasterKeys_.contains(pubKey)) return pubKey; return std::nullopt; diff --git a/src/xrpld/app/misc/detail/ValidatorSite.cpp b/src/xrpld/app/misc/detail/ValidatorSite.cpp index 91352cb12d..b93a1b8007 100644 --- a/src/xrpld/app/misc/detail/ValidatorSite.cpp +++ b/src/xrpld/app/misc/detail/ValidatorSite.cpp @@ -227,12 +227,13 @@ ValidatorSite::makeRequest( { } }; - auto onFetch = - [this, siteIdx, timeoutCancel]( - error_code const& err, endpoint_type const& endpoint, detail::response_type&& resp) { - timeoutCancel(); - onSiteFetch(err, endpoint, std::move(resp), siteIdx); - }; + auto onFetch = [this, siteIdx, timeoutCancel]( + error_code const& err, + endpoint_type const& endpoint, + detail::response_type const& resp) { + timeoutCancel(); + onSiteFetch(err, endpoint, resp, siteIdx); + }; auto onFetchFile = [this, siteIdx, timeoutCancel]( error_code const& err, std::string const& resp) { diff --git a/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp b/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp index ee3f9799ad..90d3b5a8e4 100644 --- a/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp +++ b/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp @@ -400,12 +400,13 @@ SQLiteDatabase::oldestAccountTxPage(AccountTxPageOptions const& options) auto onUnsavedLedger = std::bind(saveLedgerAsync, std::ref(registry_.get().getApp()), std::placeholders::_1); AccountTxs ret; - auto onTransaction = - [&ret, &app = registry_.get().getApp()]( - std::uint32_t ledger_index, std::string const& status, Blob&& rawTxn, Blob&& rawMeta) { - convertBlobsToTxResult( - ret, ledger_index, status, std::move(rawTxn), std::move(rawMeta), app); - }; + auto onTransaction = [&ret, &app = registry_.get().getApp()]( + std::uint32_t ledger_index, + std::string const& status, + Blob const& rawTxn, + Blob const& rawMeta) { + convertBlobsToTxResult(ret, ledger_index, status, rawTxn, rawMeta, app); + }; if (existsTransaction()) { @@ -429,12 +430,13 @@ SQLiteDatabase::newestAccountTxPage(AccountTxPageOptions const& options) auto onUnsavedLedger = std::bind(saveLedgerAsync, std::ref(registry_.get().getApp()), std::placeholders::_1); AccountTxs ret; - auto onTransaction = - [&ret, &app = registry_.get().getApp()]( - std::uint32_t ledger_index, std::string const& status, Blob&& rawTxn, Blob&& rawMeta) { - convertBlobsToTxResult( - ret, ledger_index, status, std::move(rawTxn), std::move(rawMeta), app); - }; + auto onTransaction = [&ret, &app = registry_.get().getApp()]( + std::uint32_t ledger_index, + std::string const& status, + Blob const& rawTxn, + Blob const& rawMeta) { + convertBlobsToTxResult(ret, ledger_index, status, rawTxn, rawMeta, app); + }; if (existsTransaction()) { diff --git a/src/xrpld/overlay/detail/OverlayImpl.cpp b/src/xrpld/overlay/detail/OverlayImpl.cpp index aa3441f389..b4b0686ac8 100644 --- a/src/xrpld/overlay/detail/OverlayImpl.cpp +++ b/src/xrpld/overlay/detail/OverlayImpl.cpp @@ -1015,7 +1015,7 @@ OverlayImpl::getActivePeers() const Overlay::PeerSequence ret; ret.reserve(size()); - for_each([&ret](std::shared_ptr const& sp) { ret.emplace_back(std::move(sp)); }); + for_each([&ret](std::shared_ptr const& sp) { ret.emplace_back(sp); }); return ret; } @@ -1302,7 +1302,7 @@ void OverlayImpl::autoConnect() { auto const result = m_peerFinder->autoconnect(); - for (auto addr : result) + for (auto const& addr : result) connect(addr); } diff --git a/src/xrpld/overlay/detail/ProtocolMessage.h b/src/xrpld/overlay/detail/ProtocolMessage.h index 2442e48031..ac06b10292 100644 --- a/src/xrpld/overlay/detail/ProtocolMessage.h +++ b/src/xrpld/overlay/detail/ProtocolMessage.h @@ -237,7 +237,7 @@ template < std::shared_ptr parseMessageContent(MessageHeader const& header, Buffers const& buffers) { - auto const m = std::make_shared(); + auto m = std::make_shared(); ZeroCopyInputStream stream(buffers); stream.Skip(header.header_size); diff --git a/src/xrpld/peerfinder/detail/Logic.h b/src/xrpld/peerfinder/detail/Logic.h index 39f1ca6ae6..8f49da6c4f 100644 --- a/src/xrpld/peerfinder/detail/Logic.h +++ b/src/xrpld/peerfinder/detail/Logic.h @@ -452,7 +452,7 @@ public: std::vector autoconnect() { - std::vector const none; + std::vector none; std::lock_guard _(lock_); @@ -1011,7 +1011,7 @@ public: { int count(0); std::lock_guard _(lock_); - for (auto addr : list) + for (auto const& addr : list) { if (bootcache_.insertStatic(addr)) ++count; diff --git a/src/xrpld/rpc/detail/RPCCall.cpp b/src/xrpld/rpc/detail/RPCCall.cpp index c9d5d67cf3..5c57f96d79 100644 --- a/src/xrpld/rpc/detail/RPCCall.cpp +++ b/src/xrpld/rpc/detail/RPCCall.cpp @@ -395,7 +395,7 @@ private: // handle case where there is one argument of the form ip:port if (std::count(ip.begin(), ip.end(), ':') == 1) { - std::size_t colon = ip.find_last_of(":"); + std::size_t colon = ip.find_last_of(':'); jvRequest[jss::ip] = std::string{ip, 0, colon}; jvRequest[jss::port] = Json::Value{std::string{ip, colon + 1}}.asUInt(); return jvRequest; @@ -817,7 +817,8 @@ private: Json::Value jvRequest(Json::objectValue); for (auto i = 0; i < nParams; ++i) { - std::string strParam = jvParams[i].asString(); + // This was non-const. see comment below + std::string const strParam = jvParams[i].asString(); if (i == 1 && strParam.empty()) continue; @@ -827,7 +828,10 @@ private: { if (parseBase58(strParam)) { - jvRequest[accFields[i]] = std::move(strParam); + // TODO: this was std::move'd before but it does not work in practice. + // We would need a Value(std::string&&) for it to work. + // See https://github.com/XRPLF/rippled/issues/6677 + jvRequest[accFields[i]] = strParam; } else { diff --git a/src/xrpld/rpc/detail/ServerHandler.cpp b/src/xrpld/rpc/detail/ServerHandler.cpp index 64c81ccc0a..ca026104cf 100644 --- a/src/xrpld/rpc/detail/ServerHandler.cpp +++ b/src/xrpld/rpc/detail/ServerHandler.cpp @@ -79,7 +79,7 @@ authorized(Port const& port, std::map const& h) std::string strUserPass64 = it->second.substr(6); boost::trim(strUserPass64); std::string strUserPass = base64_decode(strUserPass64); - std::string::size_type nColon = strUserPass.find(":"); + std::string::size_type nColon = strUserPass.find(':'); if (nColon == std::string::npos) return false; std::string strUser = strUserPass.substr(0, nColon); diff --git a/src/xrpld/rpc/handlers/AMMInfo.cpp b/src/xrpld/rpc/handlers/AMMInfo.cpp index 42e44f004d..9204f48907 100644 --- a/src/xrpld/rpc/handlers/AMMInfo.cpp +++ b/src/xrpld/rpc/handlers/AMMInfo.cpp @@ -139,7 +139,7 @@ doAMMInfo(RPC::JsonContext& context) issue2 = (*amm)[sfAsset2].get(); } - return ValuesFromContextParams{accountID, *issue1, *issue2, std::move(amm)}; + return ValuesFromContextParams{accountID, *issue1, *issue2, amm}; }; auto const r = getValuesFromContextParams(); diff --git a/src/xrpld/rpc/handlers/AccountChannels.cpp b/src/xrpld/rpc/handlers/AccountChannels.cpp index c418386a71..7bf8a03f21 100644 --- a/src/xrpld/rpc/handlers/AccountChannels.cpp +++ b/src/xrpld/rpc/handlers/AccountChannels.cpp @@ -67,7 +67,7 @@ doAccountChannels(RPC::JsonContext& context) { return rpcError(rpcACT_MALFORMED); } - AccountID const accountID{std::move(id.value())}; + AccountID const accountID{id.value()}; if (!ledger->exists(keylet::account(accountID))) return rpcError(rpcACT_NOT_FOUND); diff --git a/src/xrpld/rpc/handlers/AccountCurrenciesHandler.cpp b/src/xrpld/rpc/handlers/AccountCurrenciesHandler.cpp index fe74c915f5..e509a72862 100644 --- a/src/xrpld/rpc/handlers/AccountCurrenciesHandler.cpp +++ b/src/xrpld/rpc/handlers/AccountCurrenciesHandler.cpp @@ -44,7 +44,7 @@ doAccountCurrencies(RPC::JsonContext& context) RPC::inject_error(rpcACT_MALFORMED, result); return result; } - auto const accountID{std::move(id.value())}; + auto const accountID{id.value()}; if (!ledger->exists(keylet::account(accountID))) return rpcError(rpcACT_NOT_FOUND); diff --git a/src/xrpld/rpc/handlers/AccountInfo.cpp b/src/xrpld/rpc/handlers/AccountInfo.cpp index 55f05ddcab..becaea8a51 100644 --- a/src/xrpld/rpc/handlers/AccountInfo.cpp +++ b/src/xrpld/rpc/handlers/AccountInfo.cpp @@ -102,7 +102,7 @@ doAccountInfo(RPC::JsonContext& context) RPC::inject_error(rpcACT_MALFORMED, result); return result; } - auto const accountID{std::move(id.value())}; + auto const accountID{id.value()}; static constexpr std::array, 9> lsFlags{ {{"defaultRipple", lsfDefaultRipple}, diff --git a/src/xrpld/rpc/handlers/AccountLines.cpp b/src/xrpld/rpc/handlers/AccountLines.cpp index 396a09b082..f7fc9bdd2d 100644 --- a/src/xrpld/rpc/handlers/AccountLines.cpp +++ b/src/xrpld/rpc/handlers/AccountLines.cpp @@ -81,7 +81,7 @@ doAccountLines(RPC::JsonContext& context) RPC::inject_error(rpcACT_MALFORMED, result); return result; } - auto const accountID{std::move(id.value())}; + auto const accountID{id.value()}; if (!ledger->exists(keylet::account(accountID))) return rpcError(rpcACT_NOT_FOUND); diff --git a/src/xrpld/rpc/handlers/AccountOffers.cpp b/src/xrpld/rpc/handlers/AccountOffers.cpp index 86ab140b03..517c0728e9 100644 --- a/src/xrpld/rpc/handlers/AccountOffers.cpp +++ b/src/xrpld/rpc/handlers/AccountOffers.cpp @@ -56,7 +56,7 @@ doAccountOffers(RPC::JsonContext& context) RPC::inject_error(rpcACT_MALFORMED, result); return result; } - auto const accountID{std::move(id.value())}; + auto const accountID{id.value()}; // Get info on account. result[jss::account] = toBase58(accountID); diff --git a/src/xrpld/rpc/handlers/AccountTx.cpp b/src/xrpld/rpc/handlers/AccountTx.cpp index 9a10e49e5d..e120c98523 100644 --- a/src/xrpld/rpc/handlers/AccountTx.cpp +++ b/src/xrpld/rpc/handlers/AccountTx.cpp @@ -133,7 +133,7 @@ getLedgerRange(RPC::Context& context, std::optional const& ledg // Does request specify a ledger or ledger range? if (ledgerSpecifier) { - auto const status = std::visit( + auto status = std::visit( [&](auto const& ls) -> RPC::Status { using T = std::decay_t; if constexpr (std::is_same_v) @@ -167,7 +167,7 @@ getLedgerRange(RPC::Context& context, std::optional const& ledg else { std::shared_ptr ledgerView; - auto const status = getLedger(ledgerView, ls, context); + auto status = getLedger(ledgerView, ls, context); if (!ledgerView) { return status; diff --git a/src/xrpld/rpc/handlers/DepositAuthorized.cpp b/src/xrpld/rpc/handlers/DepositAuthorized.cpp index b2fc13415e..fb1c0db884 100644 --- a/src/xrpld/rpc/handlers/DepositAuthorized.cpp +++ b/src/xrpld/rpc/handlers/DepositAuthorized.cpp @@ -35,7 +35,7 @@ doDepositAuthorized(RPC::JsonContext& context) auto srcID = parseBase58(params[jss::source_account].asString()); if (!srcID) return rpcError(rpcACT_MALFORMED); - auto const srcAcct{std::move(srcID.value())}; + auto const srcAcct{srcID.value()}; // Validate destination_account. if (!params.isMember(jss::destination_account)) @@ -49,7 +49,7 @@ doDepositAuthorized(RPC::JsonContext& context) auto dstID = parseBase58(params[jss::destination_account].asString()); if (!dstID) return rpcError(rpcACT_MALFORMED); - auto const dstAcct{std::move(dstID.value())}; + auto const dstAcct{dstID.value()}; // Validate ledger. std::shared_ptr ledger; diff --git a/src/xrpld/rpc/handlers/GatewayBalances.cpp b/src/xrpld/rpc/handlers/GatewayBalances.cpp index 914725de60..8d03a3961d 100644 --- a/src/xrpld/rpc/handlers/GatewayBalances.cpp +++ b/src/xrpld/rpc/handlers/GatewayBalances.cpp @@ -55,7 +55,7 @@ doGatewayBalances(RPC::JsonContext& context) auto id = parseBase58(strIdent); if (!id) return rpcError(rpcACT_MALFORMED); - auto const accountID{std::move(id.value())}; + auto const accountID{id.value()}; context.loadType = Resource::feeHeavyBurdenRPC; result[jss::account] = toBase58(accountID); @@ -76,7 +76,7 @@ doGatewayBalances(RPC::JsonContext& context) { if (auto id = parseBase58(j.asString()); id) { - hotWallets.insert(std::move(id.value())); + hotWallets.insert(id.value()); return true; } } diff --git a/src/xrpld/rpc/handlers/LedgerEntry.cpp b/src/xrpld/rpc/handlers/LedgerEntry.cpp index 640369c04b..c7a47a0517 100644 --- a/src/xrpld/rpc/handlers/LedgerEntry.cpp +++ b/src/xrpld/rpc/handlers/LedgerEntry.cpp @@ -328,7 +328,7 @@ parseDepositPreauth( "malformedAuthorizedCredentials", jss::authorized_credentials, "array"); } - return keylet::depositPreauth(*owner, std::move(sorted)).key; + return keylet::depositPreauth(*owner, sorted).key; } static Expected diff --git a/src/xrpld/rpc/handlers/LedgerEntryHelpers.h b/src/xrpld/rpc/handlers/LedgerEntryHelpers.h index 683e6ebb5a..9182c9cfd7 100644 --- a/src/xrpld/rpc/handlers/LedgerEntryHelpers.h +++ b/src/xrpld/rpc/handlers/LedgerEntryHelpers.h @@ -20,10 +20,9 @@ Unexpected missingFieldError(Json::StaticString const field, std::optional err = std::nullopt) { Json::Value json = Json::objectValue; - auto error = RPC::missing_field_message(std::string(field.c_str())); json[jss::error] = err.value_or("malformedRequest"); json[jss::error_code] = rpcINVALID_PARAMS; - json[jss::error_message] = std::move(error); + json[jss::error_message] = RPC::missing_field_message(std::string(field.c_str())); return Unexpected(json); } @@ -31,10 +30,9 @@ Unexpected invalidFieldError(std::string const& err, Json::StaticString const field, std::string const& type) { Json::Value json = Json::objectValue; - auto error = RPC::expected_field_message(field, type); json[jss::error] = err; json[jss::error_code] = rpcINVALID_PARAMS; - json[jss::error_message] = std::move(error); + json[jss::error_message] = RPC::expected_field_message(field, type); return Unexpected(json); } @@ -118,7 +116,7 @@ parseHexBlob(Json::Value const& param, std::size_t maxLength) if (!param.isString()) return std::nullopt; - auto const blob = strUnHex(param.asString()); + auto blob = strUnHex(param.asString()); if (!blob || blob->empty() || blob->size() > maxLength) return std::nullopt; diff --git a/src/xrpld/rpc/handlers/NoRippleCheck.cpp b/src/xrpld/rpc/handlers/NoRippleCheck.cpp index 7b780f3b16..c3e36280a6 100644 --- a/src/xrpld/rpc/handlers/NoRippleCheck.cpp +++ b/src/xrpld/rpc/handlers/NoRippleCheck.cpp @@ -98,7 +98,7 @@ doNoRippleCheck(RPC::JsonContext& context) RPC::inject_error(rpcACT_MALFORMED, result); return result; } - auto const accountID{std::move(id.value())}; + auto const accountID{id.value()}; auto const sle = ledger->read(keylet::account(accountID)); if (!sle) return rpcError(rpcACT_NOT_FOUND); diff --git a/src/xrpld/rpc/handlers/ServerDefinitions.cpp b/src/xrpld/rpc/handlers/ServerDefinitions.cpp index e4f08d6dec..2f11e18efb 100644 --- a/src/xrpld/rpc/handlers/ServerDefinitions.cpp +++ b/src/xrpld/rpc/handlers/ServerDefinitions.cpp @@ -93,7 +93,7 @@ ServerDefinitions::translate(std::string const& inp) // convert snake_case to CamelCase for (;;) { - pos = inpToProcess.find("_"); + pos = inpToProcess.find('_'); if (pos == std::string::npos) pos = inpToProcess.size(); std::string token = inpToProcess.substr(0, pos);