From 420ee918774da63724fb5e1f08af7cc60e195afd Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sun, 19 Aug 2012 19:23:10 -0700 Subject: [PATCH] Remove more wasteful allocate/increment/decrement/free cycles. --- src/AccountState.cpp | 3 ++- src/AccountState.h | 4 ++-- src/LedgerAcquire.cpp | 2 +- src/LedgerAcquire.h | 2 +- src/LedgerConsensus.cpp | 28 ++++++++++++++-------------- src/LedgerConsensus.h | 30 +++++++++++++++--------------- src/LedgerHistory.cpp | 3 ++- src/LedgerMaster.cpp | 10 +++++----- src/LedgerMaster.h | 14 +++++++------- src/NetworkOPs.cpp | 2 +- src/NetworkOPs.h | 2 +- 11 files changed, 51 insertions(+), 49 deletions(-) diff --git a/src/AccountState.cpp b/src/AccountState.cpp index 1f84c9dce9..e9804926c2 100644 --- a/src/AccountState.cpp +++ b/src/AccountState.cpp @@ -19,7 +19,8 @@ AccountState::AccountState(const NewcoinAddress& id) : mValid(false) mValid = true; } -AccountState::AccountState(SerializedLedgerEntry::pointer ledgerEntry) : mLedgerEntry(ledgerEntry), mValid(false) +AccountState::AccountState(const SerializedLedgerEntry::pointer& ledgerEntry) : + mLedgerEntry(ledgerEntry), mValid(false) { if (!mLedgerEntry) return; if (mLedgerEntry->getType() != ltACCOUNT_ROOT) return; diff --git a/src/AccountState.h b/src/AccountState.h index b2e5a0c95a..9069f375b0 100644 --- a/src/AccountState.h +++ b/src/AccountState.h @@ -27,8 +27,8 @@ private: bool mValid; public: - AccountState(const NewcoinAddress& AccountID); // For new accounts - AccountState(SerializedLedgerEntry::pointer ledgerEntry); // For accounts in a ledger + AccountState(const NewcoinAddress& AccountID); // For new accounts + AccountState(const SerializedLedgerEntry::pointer& ledgerEntry); // For accounts in a ledger bool bHaveAuthorizedKey() { diff --git a/src/LedgerAcquire.cpp b/src/LedgerAcquire.cpp index d2189e693f..949cc7e851 100644 --- a/src/LedgerAcquire.cpp +++ b/src/LedgerAcquire.cpp @@ -257,7 +257,7 @@ void LedgerAcquire::trigger(const Peer::pointer& peer, bool timer) resetTimer(); } -void PeerSet::sendRequest(const newcoin::TMGetLedger& tmGL, Peer::pointer peer) +void PeerSet::sendRequest(const newcoin::TMGetLedger& tmGL, const Peer::pointer& peer) { if (!peer) sendRequest(tmGL); diff --git a/src/LedgerAcquire.h b/src/LedgerAcquire.h index 3ea334bd10..ff92ad4ef8 100644 --- a/src/LedgerAcquire.h +++ b/src/LedgerAcquire.h @@ -31,7 +31,7 @@ protected: virtual ~PeerSet() { ; } void sendRequest(const newcoin::TMGetLedger& message); - void sendRequest(const newcoin::TMGetLedger& message, Peer::pointer peer); + void sendRequest(const newcoin::TMGetLedger& message, const Peer::pointer& peer); public: const uint256& getHash() const { return mHash; } diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index 2b45f3b8c4..52e4173c1c 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -83,7 +83,7 @@ void TransactionAcquire::trigger(const Peer::pointer& peer, bool timer) } bool TransactionAcquire::takeNodes(const std::list& nodeIDs, - const std::list< std::vector >& data, Peer::pointer peer) + const std::list< std::vector >& data, const Peer::pointer& peer) { if (mComplete) return true; @@ -191,7 +191,7 @@ bool LCTransaction::updatePosition(int percentTime, bool proposing) return true; } -LedgerConsensus::LedgerConsensus(const uint256& prevLCLHash, Ledger::pointer previousLedger, uint32 closeTime) +LedgerConsensus::LedgerConsensus(const uint256& prevLCLHash, const Ledger::pointer& previousLedger, uint32 closeTime) : mState(lcsPRE_CLOSE), mCloseTime(closeTime), mPrevLedgerHash(prevLCLHash), mPreviousLedger(previousLedger), mCurrentMSeconds(0), mClosePercent(0), mHaveCloseTimeConsensus(false) { @@ -297,7 +297,7 @@ void LedgerConsensus::takeInitialPosition(Ledger& initialLedger) propose(std::vector(), std::vector()); } -void LedgerConsensus::createDisputes(SHAMap::pointer m1, SHAMap::pointer m2) +void LedgerConsensus::createDisputes(const SHAMap::pointer& m1, const SHAMap::pointer& m2) { SHAMap::SHAMapDiff differences; m1->compare(m2, differences, 16384); @@ -317,7 +317,7 @@ void LedgerConsensus::createDisputes(SHAMap::pointer m1, SHAMap::pointer m2) } } -void LedgerConsensus::mapComplete(const uint256& hash, SHAMap::pointer map, bool acquired) +void LedgerConsensus::mapComplete(const uint256& hash, const SHAMap::pointer& map, bool acquired) { if (acquired) Log(lsINFO) << "We have acquired TXS " << hash.GetHex(); @@ -370,7 +370,7 @@ void LedgerConsensus::sendHaveTxSet(const uint256& hash, bool direct) theApp->getConnectionPool().relayMessage(NULL, packet); } -void LedgerConsensus::adjustCount(SHAMap::pointer map, const std::vector& peers) +void LedgerConsensus::adjustCount(const SHAMap::pointer& map, const std::vector& peers) { // Adjust the counts on all disputed transactions based on the set of peers taking this position for (boost::unordered_map::iterator it = mDisputes.begin(), end = mDisputes.end(); it != end; ++it) @@ -645,7 +645,7 @@ SHAMap::pointer LedgerConsensus::getTransactionTree(const uint256& hash, bool do return it->second; } -void LedgerConsensus::startAcquiring(TransactionAcquire::pointer acquire) +void LedgerConsensus::startAcquiring(const TransactionAcquire::pointer& acquire) { boost::unordered_map< uint256, std::vector< boost::weak_ptr > >::iterator it = mPeerData.find(acquire->getHash()); @@ -713,7 +713,7 @@ void LedgerConsensus::addDisputedTransaction(const uint256& txID, const std::vec } } -bool LedgerConsensus::peerPosition(LedgerProposal::pointer newPosition) +bool LedgerConsensus::peerPosition(const LedgerProposal::pointer& newPosition) { LedgerProposal::pointer& currentPosition = mPeerPositions[newPosition->getPeerID()]; @@ -746,7 +746,7 @@ bool LedgerConsensus::peerPosition(LedgerProposal::pointer newPosition) return true; } -bool LedgerConsensus::peerHasSet(Peer::pointer peer, const uint256& hashSet, newcoin::TxSetStatus status) +bool LedgerConsensus::peerHasSet(const Peer::pointer& peer, const uint256& hashSet, newcoin::TxSetStatus status) { if (status != newcoin::tsHAVE) // Indirect requests are for future support return true; @@ -763,7 +763,7 @@ bool LedgerConsensus::peerHasSet(Peer::pointer peer, const uint256& hashSet, new return true; } -bool LedgerConsensus::peerGaveNodes(Peer::pointer peer, const uint256& setHash, +bool LedgerConsensus::peerGaveNodes(const Peer::pointer& peer, const uint256& setHash, const std::list& nodeIDs, const std::list< std::vector >& nodeData) { boost::unordered_map::iterator acq = mAcquiring.find(setHash); @@ -791,8 +791,8 @@ void LedgerConsensus::Saccept(boost::shared_ptr This, SHAMap::p This->accept(txSet); } -void LedgerConsensus::applyTransaction(TransactionEngine& engine, SerializedTransaction::pointer txn, - Ledger::pointer ledger, CanonicalTXSet& failedTransactions, bool final) +void LedgerConsensus::applyTransaction(TransactionEngine& engine, const SerializedTransaction::pointer& txn, + const Ledger::pointer& ledger, CanonicalTXSet& failedTransactions, bool final) { TransactionEngineParams parms = final ? (tepNO_CHECK_FEE | tepUPDATE_TOTAL | tepMETADATA) : tepNONE; #ifndef TRUST_NETWORK @@ -824,8 +824,8 @@ void LedgerConsensus::applyTransaction(TransactionEngine& engine, SerializedTran #endif } -void LedgerConsensus::applyTransactions(SHAMap::pointer set, Ledger::pointer applyLedger, Ledger::pointer checkLedger, - CanonicalTXSet& failedTransactions, bool final) +void LedgerConsensus::applyTransactions(const SHAMap::pointer& set, const Ledger::pointer& applyLedger, + const Ledger::pointer& checkLedger, CanonicalTXSet& failedTransactions, bool final) { TransactionEngineParams parms = final ? (tepNO_CHECK_FEE | tepUPDATE_TOTAL) : tepNONE; TransactionEngine engine(applyLedger); @@ -881,7 +881,7 @@ void LedgerConsensus::applyTransactions(SHAMap::pointer set, Ledger::pointer app } while (successes > 0); } -void LedgerConsensus::accept(SHAMap::pointer set) +void LedgerConsensus::accept(const SHAMap::pointer& set) { assert(set->getHash() == mOurPosition->getCurrentHash()); diff --git a/src/LedgerConsensus.h b/src/LedgerConsensus.h index cadfb23acd..e95ed6328a 100644 --- a/src/LedgerConsensus.h +++ b/src/LedgerConsensus.h @@ -41,7 +41,7 @@ public: SHAMap::pointer getMap() { return mMap; } bool takeNodes(const std::list& IDs, const std::list< std::vector >& data, - Peer::pointer); + const Peer::pointer&); }; class LCTransaction @@ -113,24 +113,24 @@ protected: // final accept logic static void Saccept(boost::shared_ptr This, SHAMap::pointer txSet); - void accept(SHAMap::pointer txSet); + void accept(const SHAMap::pointer& txSet); - void weHave(const uint256& id, Peer::pointer avoidPeer); - void startAcquiring(TransactionAcquire::pointer); + void weHave(const uint256& id, const Peer::pointer& avoidPeer); + void startAcquiring(const TransactionAcquire::pointer&); SHAMap::pointer find(const uint256& hash); - void createDisputes(SHAMap::pointer, SHAMap::pointer); + void createDisputes(const SHAMap::pointer&, const SHAMap::pointer&); void addDisputedTransaction(const uint256&, const std::vector& transaction); - void adjustCount(SHAMap::pointer map, const std::vector& peers); + void adjustCount(const SHAMap::pointer& map, const std::vector& peers); void propose(const std::vector& addedTx, const std::vector& removedTx); void addPosition(LedgerProposal&, bool ours); void removePosition(LedgerProposal&, bool ours); void sendHaveTxSet(const uint256& set, bool direct); - void applyTransactions(SHAMap::pointer transactionSet, Ledger::pointer targetLedger, Ledger::pointer checkLedger, - CanonicalTXSet& failedTransactions, bool final); - void applyTransaction(TransactionEngine& engine, SerializedTransaction::pointer txn, Ledger::pointer targetLedger, - CanonicalTXSet& failedTransactions, bool final); + void applyTransactions(const SHAMap::pointer& transactionSet, const Ledger::pointer& targetLedger, + const Ledger::pointer& checkLedger, CanonicalTXSet& failedTransactions, bool final); + void applyTransaction(TransactionEngine& engine, const SerializedTransaction::pointer& txn, + const Ledger::pointer& targetLedger, CanonicalTXSet& failedTransactions, bool final); // manipulating our own position void statusChange(newcoin::NodeEvent, Ledger& ledger); @@ -141,7 +141,7 @@ protected: void endConsensus(); public: - LedgerConsensus(const uint256& prevLCLHash, Ledger::pointer previousLedger, uint32 closeTime); + LedgerConsensus(const uint256& prevLCLHash, const Ledger::pointer& previousLedger, uint32 closeTime); int startup(); Json::Value getJson(); @@ -151,7 +151,7 @@ public: SHAMap::pointer getTransactionTree(const uint256& hash, bool doAcquire); TransactionAcquire::pointer getAcquiring(const uint256& hash); - void mapComplete(const uint256& hash, SHAMap::pointer map, bool acquired); + void mapComplete(const uint256& hash, const SHAMap::pointer& map, bool acquired); void checkLCL(); void timerEntry(); @@ -165,11 +165,11 @@ public: bool haveConsensus(); - bool peerPosition(LedgerProposal::pointer); + bool peerPosition(const LedgerProposal::pointer&); - bool peerHasSet(Peer::pointer peer, const uint256& set, newcoin::TxSetStatus status); + bool peerHasSet(const Peer::pointer& peer, const uint256& set, newcoin::TxSetStatus status); - bool peerGaveNodes(Peer::pointer peer, const uint256& setHash, + bool peerGaveNodes(const Peer::pointer& peer, const uint256& setHash, const std::list& nodeIDs, const std::list< std::vector >& nodeData); }; diff --git a/src/LedgerHistory.cpp b/src/LedgerHistory.cpp index 0445b268d5..6dd3a9c4a3 100644 --- a/src/LedgerHistory.cpp +++ b/src/LedgerHistory.cpp @@ -90,7 +90,8 @@ Ledger::pointer LedgerHistory::canonicalizeLedger(Ledger::pointer ledger, bool s if (!save) { // return input ledger if not in map, otherwise, return corresponding map ledger Ledger::pointer ret = mLedgersByHash.fetch(h); - if (ret) return ret; + if (ret) + return ret; return ledger; } diff --git a/src/LedgerMaster.cpp b/src/LedgerMaster.cpp index 7350b85349..e7b571f361 100644 --- a/src/LedgerMaster.cpp +++ b/src/LedgerMaster.cpp @@ -13,13 +13,13 @@ uint32 LedgerMaster::getCurrentLedgerIndex() return mCurrentLedger->getLedgerSeq(); } -bool LedgerMaster::addHeldTransaction(Transaction::pointer transaction) +bool LedgerMaster::addHeldTransaction(const Transaction::pointer& transaction) { // returns true if transaction was added boost::recursive_mutex::scoped_lock ml(mLock); return mHeldTransactionsByID.insert(std::make_pair(transaction->getID(), transaction)).second; } -void LedgerMaster::pushLedger(Ledger::pointer newLedger) +void LedgerMaster::pushLedger(const Ledger::pointer& newLedger) { // Caller should already have properly assembled this ledger into "ready-to-close" form -- // all candidate transactions must already be appled @@ -35,7 +35,7 @@ void LedgerMaster::pushLedger(Ledger::pointer newLedger) mEngine.setLedger(newLedger); } -void LedgerMaster::pushLedger(Ledger::pointer newLCL, Ledger::pointer newOL) +void LedgerMaster::pushLedger(const Ledger::pointer& newLCL, const Ledger::pointer& newOL) { assert(newLCL->isClosed() && newLCL->isAccepted()); assert(!newOL->isClosed() && !newOL->isAccepted()); @@ -54,7 +54,7 @@ void LedgerMaster::pushLedger(Ledger::pointer newLCL, Ledger::pointer newOL) mEngine.setLedger(newOL); } -void LedgerMaster::switchLedgers(Ledger::pointer lastClosed, Ledger::pointer current) +void LedgerMaster::switchLedgers(const Ledger::pointer& lastClosed, const Ledger::pointer& current) { assert(lastClosed && current); mFinalizedLedger = lastClosed; @@ -66,7 +66,7 @@ void LedgerMaster::switchLedgers(Ledger::pointer lastClosed, Ledger::pointer cur mEngine.setLedger(mCurrentLedger); } -void LedgerMaster::storeLedger(Ledger::pointer ledger) +void LedgerMaster::storeLedger(const Ledger::pointer& ledger) { mLedgerHistory.addLedger(ledger); } diff --git a/src/LedgerMaster.h b/src/LedgerMaster.h index 187aaeec13..dd51333283 100644 --- a/src/LedgerMaster.h +++ b/src/LedgerMaster.h @@ -26,8 +26,8 @@ class LedgerMaster std::map mHeldTransactionsByID; void applyFutureTransactions(uint32 ledgerIndex); - bool isValidTransaction(Transaction::pointer trans); - bool isTransactionOnFutureList(Transaction::pointer trans); + bool isValidTransaction(const Transaction::pointer& trans); + bool isTransactionOnFutureList(const Transaction::pointer& trans); public: @@ -48,11 +48,11 @@ public: TransactionEngineResult doTransaction(const SerializedTransaction& txn, uint32 targetLedger, TransactionEngineParams params); - void pushLedger(Ledger::pointer newLedger); - void pushLedger(Ledger::pointer newLCL, Ledger::pointer newOL); - void storeLedger(Ledger::pointer); + void pushLedger(const Ledger::pointer& newLedger); + void pushLedger(const Ledger::pointer& newLCL, const Ledger::pointer& newOL); + void storeLedger(const Ledger::pointer&); - void switchLedgers(Ledger::pointer lastClosed, Ledger::pointer newCurrent); + void switchLedgers(const Ledger::pointer& lastClosed, const Ledger::pointer& newCurrent); Ledger::pointer closeLedger(); @@ -74,7 +74,7 @@ public: return mLedgerHistory.getLedgerByHash(hash); } - bool addHeldTransaction(Transaction::pointer trans); + bool addHeldTransaction(const Transaction::pointer& trans); }; #endif diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index a0e7811425..4d3fd7aee2 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -52,7 +52,7 @@ uint32 NetworkOPs::getCurrentLedgerID() } // Sterilize transaction through serialization. -Transaction::pointer NetworkOPs::submitTransaction(Transaction::pointer tpTrans) +Transaction::pointer NetworkOPs::submitTransaction(const Transaction::pointer& tpTrans) { Serializer s; diff --git a/src/NetworkOPs.h b/src/NetworkOPs.h index 52e1329f8d..79dc6ae138 100644 --- a/src/NetworkOPs.h +++ b/src/NetworkOPs.h @@ -108,7 +108,7 @@ public: // // Transaction operations // - Transaction::pointer submitTransaction(Transaction::pointer tpTrans); + Transaction::pointer submitTransaction(const Transaction::pointer& tpTrans); Transaction::pointer processTransaction(Transaction::pointer transaction, uint32 targetLedger = 0, Peer* source = NULL);