Remove more wasteful allocate/increment/decrement/free cycles.

This commit is contained in:
JoelKatz
2012-08-19 19:23:10 -07:00
parent 84ee39b147
commit 420ee91877
11 changed files with 51 additions and 49 deletions

View File

@@ -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;

View File

@@ -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()
{

View File

@@ -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);

View File

@@ -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; }

View File

@@ -83,7 +83,7 @@ void TransactionAcquire::trigger(const Peer::pointer& peer, bool timer)
}
bool TransactionAcquire::takeNodes(const std::list<SHAMapNode>& nodeIDs,
const std::list< std::vector<unsigned char> >& data, Peer::pointer peer)
const std::list< std::vector<unsigned char> >& 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<uint256>(), std::vector<uint256>());
}
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<uint160>& peers)
void LedgerConsensus::adjustCount(const SHAMap::pointer& map, const std::vector<uint160>& peers)
{ // Adjust the counts on all disputed transactions based on the set of peers taking this position
for (boost::unordered_map<uint256, LCTransaction::pointer>::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<Peer> > >::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<SHAMapNode>& nodeIDs, const std::list< std::vector<unsigned char> >& nodeData)
{
boost::unordered_map<uint256, TransactionAcquire::pointer>::iterator acq = mAcquiring.find(setHash);
@@ -791,8 +791,8 @@ void LedgerConsensus::Saccept(boost::shared_ptr<LedgerConsensus> 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());

View File

@@ -41,7 +41,7 @@ public:
SHAMap::pointer getMap() { return mMap; }
bool takeNodes(const std::list<SHAMapNode>& IDs, const std::list< std::vector<unsigned char> >& data,
Peer::pointer);
const Peer::pointer&);
};
class LCTransaction
@@ -113,24 +113,24 @@ protected:
// final accept logic
static void Saccept(boost::shared_ptr<LedgerConsensus> 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<unsigned char>& transaction);
void adjustCount(SHAMap::pointer map, const std::vector<uint160>& peers);
void adjustCount(const SHAMap::pointer& map, const std::vector<uint160>& peers);
void propose(const std::vector<uint256>& addedTx, const std::vector<uint256>& 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<SHAMapNode>& nodeIDs, const std::list< std::vector<unsigned char> >& nodeData);
};

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -26,8 +26,8 @@ class LedgerMaster
std::map<uint256, Transaction::pointer> 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

View File

@@ -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;

View File

@@ -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);