mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Fix a few more cases where we create a new shared pointer just to
immediately throw it away, resulting in a wasted allocate/increment/decrement/free.
This commit is contained in:
@@ -37,7 +37,7 @@ bool CanonicalTXKey::operator>=(const CanonicalTXKey& key)const
|
||||
return mTXid >= key.mTXid;
|
||||
}
|
||||
|
||||
void CanonicalTXSet::push_back(SerializedTransaction::pointer txn)
|
||||
void CanonicalTXSet::push_back(const SerializedTransaction::pointer& txn)
|
||||
{
|
||||
uint256 effectiveAccount = mSetHash;
|
||||
effectiveAccount ^= txn->getSourceAccount().getAccountID().to256();
|
||||
|
||||
@@ -38,7 +38,7 @@ protected:
|
||||
public:
|
||||
CanonicalTXSet(const uint256& lclHash) : mSetHash(lclHash) { ; }
|
||||
|
||||
void push_back(SerializedTransaction::pointer txn);
|
||||
void push_back(const SerializedTransaction::pointer& txn);
|
||||
iterator erase(const iterator& it);
|
||||
|
||||
iterator begin() { return mMap.begin(); }
|
||||
|
||||
@@ -226,7 +226,7 @@ void ConnectionPool::policyHandler(const boost::system::error_code& ecResult)
|
||||
|
||||
// YYY: Should probably do this in the background.
|
||||
// YYY: Might end up sending to disconnected peer?
|
||||
void ConnectionPool::relayMessage(Peer* fromPeer, PackedMessage::pointer msg)
|
||||
void ConnectionPool::relayMessage(Peer* fromPeer, const PackedMessage::pointer& msg)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mPeerLock);
|
||||
|
||||
@@ -339,7 +339,8 @@ std::vector<Peer::pointer> ConnectionPool::getPeerVector()
|
||||
|
||||
// Now know peer's node public key. Determine if we want to stay connected.
|
||||
// <-- bNew: false = redundant
|
||||
bool ConnectionPool::peerConnected(Peer::pointer peer, const NewcoinAddress& naPeer, const std::string& strIP, int iPort)
|
||||
bool ConnectionPool::peerConnected(const Peer::pointer& peer, const NewcoinAddress& naPeer,
|
||||
const std::string& strIP, int iPort)
|
||||
{
|
||||
bool bNew = false;
|
||||
|
||||
@@ -397,7 +398,7 @@ bool ConnectionPool::peerConnected(Peer::pointer peer, const NewcoinAddress& naP
|
||||
}
|
||||
|
||||
// We maintain a map of public key to peer for connected and verified peers. Maintain it.
|
||||
void ConnectionPool::peerDisconnected(Peer::pointer peer, const NewcoinAddress& naPeer)
|
||||
void ConnectionPool::peerDisconnected(const Peer::pointer& peer, const NewcoinAddress& naPeer)
|
||||
{
|
||||
if (naPeer.isValid())
|
||||
{
|
||||
@@ -484,7 +485,7 @@ bool ConnectionPool::peerScanSet(const std::string& strIp, int iPort)
|
||||
}
|
||||
|
||||
// --> strIp: not empty
|
||||
void ConnectionPool::peerClosed(Peer::pointer peer, const std::string& strIp, int iPort)
|
||||
void ConnectionPool::peerClosed(const Peer::pointer& peer, const std::string& strIp, int iPort)
|
||||
{
|
||||
ipPort ipPeer = make_pair(strIp, iPort);
|
||||
bool bScanRefresh = false;
|
||||
@@ -539,7 +540,7 @@ void ConnectionPool::peerClosed(Peer::pointer peer, const std::string& strIp, in
|
||||
scanRefresh();
|
||||
}
|
||||
|
||||
void ConnectionPool::peerVerified(Peer::pointer peer)
|
||||
void ConnectionPool::peerVerified(const Peer::pointer& peer)
|
||||
{
|
||||
if (mScanning && mScanning == peer)
|
||||
{
|
||||
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
void start();
|
||||
|
||||
// Send message to network.
|
||||
void relayMessage(Peer* fromPeer, PackedMessage::pointer msg);
|
||||
void relayMessage(Peer* fromPeer, const PackedMessage::pointer& msg);
|
||||
|
||||
// Manual connection request.
|
||||
// Queue for immediate scanning.
|
||||
@@ -72,16 +72,16 @@ public:
|
||||
|
||||
// We know peers node public key.
|
||||
// <-- bool: false=reject
|
||||
bool peerConnected(Peer::pointer peer, const NewcoinAddress& naPeer, const std::string& strIP, int iPort);
|
||||
bool peerConnected(const Peer::pointer& peer, const NewcoinAddress& naPeer, const std::string& strIP, int iPort);
|
||||
|
||||
// No longer connected.
|
||||
void peerDisconnected(Peer::pointer peer, const NewcoinAddress& naPeer);
|
||||
void peerDisconnected(const Peer::pointer& peer, const NewcoinAddress& naPeer);
|
||||
|
||||
// As client accepted.
|
||||
void peerVerified(Peer::pointer peer);
|
||||
void peerVerified(const Peer::pointer& peer);
|
||||
|
||||
// As client failed connect and be accepted.
|
||||
void peerClosed(Peer::pointer peer, const std::string& strIp, int iPort);
|
||||
void peerClosed(const Peer::pointer& peer, const std::string& strIp, int iPort);
|
||||
|
||||
Json::Value getPeersJson();
|
||||
std::vector<Peer::pointer> getPeerVector();
|
||||
@@ -98,11 +98,6 @@ public:
|
||||
void policyLowWater();
|
||||
void policyEnforce();
|
||||
|
||||
#if 0
|
||||
//std::vector<std::pair<PackedMessage::pointer,int> > mBroadcastMessages;
|
||||
|
||||
bool isMessageKnown(PackedMessage::pointer msg);
|
||||
#endif
|
||||
};
|
||||
|
||||
extern void splitIpPort(const std::string& strIpPort, std::string& strIp, int& iPort);
|
||||
|
||||
@@ -210,7 +210,7 @@ RippleState::pointer Ledger::accessRippleState(const uint256& uNode)
|
||||
return boost::make_shared<RippleState>(sle);
|
||||
}
|
||||
|
||||
bool Ledger::addTransaction(Transaction::pointer trans)
|
||||
bool Ledger::addTransaction(const Transaction::pointer& trans)
|
||||
{ // low-level - just add to table
|
||||
assert(!mAccepted);
|
||||
assert(trans->getID().isNonZero());
|
||||
@@ -257,7 +257,7 @@ uint256 Ledger::getHash()
|
||||
return(mHash);
|
||||
}
|
||||
|
||||
void Ledger::saveAcceptedLedger(Ledger::pointer ledger)
|
||||
void Ledger::saveAcceptedLedger(const Ledger::pointer& ledger)
|
||||
{
|
||||
static boost::format ledgerExists("SELECT LedgerSeq FROM Ledgers where LedgerSeq = %d;");
|
||||
static boost::format deleteLedger("DELETE FROM Ledgers WHERE LedgerSeq = %d;");
|
||||
|
||||
@@ -81,7 +81,7 @@ private:
|
||||
|
||||
protected:
|
||||
|
||||
bool addTransaction(Transaction::pointer);
|
||||
bool addTransaction(const Transaction::pointer&);
|
||||
bool addTransaction(const uint256& id, const Serializer& txn);
|
||||
|
||||
static Ledger::pointer getSQL(const std::string& sqlStatement);
|
||||
@@ -156,12 +156,12 @@ public:
|
||||
|
||||
// high-level functions
|
||||
AccountState::pointer getAccountState(const NewcoinAddress& acctID);
|
||||
LedgerStateParms writeBack(LedgerStateParms parms, SLE::pointer);
|
||||
LedgerStateParms writeBack(LedgerStateParms parms, const SLE::pointer&);
|
||||
SLE::pointer getAccountRoot(const uint160& accountID);
|
||||
SLE::pointer getAccountRoot(const NewcoinAddress& naAccountID);
|
||||
|
||||
// database functions
|
||||
static void saveAcceptedLedger(Ledger::pointer);
|
||||
static void saveAcceptedLedger(const Ledger::pointer&);
|
||||
static Ledger::pointer loadByIndex(uint32 ledgerIndex);
|
||||
static Ledger::pointer loadByHash(const uint256& ledgerHash);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
// XXX Use shared locks where possible?
|
||||
|
||||
LedgerStateParms Ledger::writeBack(LedgerStateParms parms, SLE::pointer entry)
|
||||
LedgerStateParms Ledger::writeBack(LedgerStateParms parms, const SLE::pointer& entry)
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
bool create = false;
|
||||
|
||||
@@ -498,7 +498,7 @@ bool SHAMap::delItem(const uint256& id)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction, bool hasMeta)
|
||||
bool SHAMap::addGiveItem(const SHAMapItem::pointer& item, bool isTransaction, bool hasMeta)
|
||||
{ // add the specified item, does not update
|
||||
#ifdef ST_DEBUG
|
||||
std::cerr << "aGI " << item->getTag().GetHex() << std::endl;
|
||||
@@ -596,7 +596,7 @@ bool SHAMap::addItem(const SHAMapItem& i, bool isTransaction, bool hasMetaData)
|
||||
return addGiveItem(boost::make_shared<SHAMapItem>(i), isTransaction, hasMetaData);
|
||||
}
|
||||
|
||||
bool SHAMap::updateGiveItem(SHAMapItem::pointer item, bool isTransaction, bool hasMeta)
|
||||
bool SHAMap::updateGiveItem(const SHAMapItem::pointer& item, bool isTransaction, bool hasMeta)
|
||||
{ // can't change the tag but can change the hash
|
||||
uint256 tag = item->getTag();
|
||||
|
||||
|
||||
10
src/SHAMap.h
10
src/SHAMap.h
@@ -160,7 +160,7 @@ private:
|
||||
public:
|
||||
SHAMapTreeNode(uint32 seq, const SHAMapNode& nodeID); // empty node
|
||||
SHAMapTreeNode(const SHAMapTreeNode& node, uint32 seq); // copy node from older tree
|
||||
SHAMapTreeNode(const SHAMapNode& nodeID, SHAMapItem::pointer item, TNType type, uint32 seq);
|
||||
SHAMapTreeNode(const SHAMapNode& nodeID, const SHAMapItem::pointer& item, TNType type, uint32 seq);
|
||||
|
||||
// raw node functions
|
||||
SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned char>& data, uint32 seq, SHANodeFormat format);
|
||||
@@ -199,7 +199,7 @@ public:
|
||||
bool hasItem() const { return !!mItem; }
|
||||
SHAMapItem::pointer peekItem() { return mItem; }
|
||||
SHAMapItem::pointer getItem() const;
|
||||
bool setItem(SHAMapItem::pointer& i, TNType type);
|
||||
bool setItem(const SHAMapItem::pointer& i, TNType type);
|
||||
const uint256& getTag() const { return mItem->getTag(); }
|
||||
const std::vector<unsigned char>& peekData() { return mItem->peekData(); }
|
||||
std::vector<unsigned char> getData() const { return mItem->getData(); }
|
||||
@@ -311,8 +311,8 @@ public:
|
||||
uint256 getHash() { return root->getNodeHash(); }
|
||||
|
||||
// save a copy if you have a temporary anyway
|
||||
bool updateGiveItem(SHAMapItem::pointer, bool isTransaction, bool hasMeta);
|
||||
bool addGiveItem(SHAMapItem::pointer, bool isTransaction, bool hasMeta);
|
||||
bool updateGiveItem(const SHAMapItem::pointer&, bool isTransaction, bool hasMeta);
|
||||
bool addGiveItem(const SHAMapItem::pointer&, bool isTransaction, bool hasMeta);
|
||||
|
||||
// save a copy if you only need a temporary
|
||||
SHAMapItem::pointer peekItem(const uint256& id);
|
||||
@@ -345,7 +345,7 @@ public:
|
||||
|
||||
// caution: otherMap must be accessed only by this function
|
||||
// return value: true=successfully completed, false=too different
|
||||
bool compare(SHAMap::pointer otherMap, SHAMapDiff& differences, int maxCount);
|
||||
bool compare(const SHAMap::pointer& otherMap, SHAMapDiff& differences, int maxCount);
|
||||
|
||||
void armDirty();
|
||||
int flushDirty(int maxNodes, HashedObjectType t, uint32 seq);
|
||||
|
||||
@@ -91,7 +91,7 @@ bool SHAMap::walkBranch(SHAMapTreeNode* node, SHAMapItem::pointer otherMapItem,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SHAMap::compare(SHAMap::pointer otherMap, SHAMapDiff& differences, int maxCount)
|
||||
bool SHAMap::compare(const SHAMap::pointer& otherMap, SHAMapDiff& differences, int maxCount)
|
||||
{ // compare two hash trees, add up to maxCount differences to the difference table
|
||||
// return value: true=complete table of differences given, false=too many differences
|
||||
// throws on corrupt tables or missing nodes
|
||||
|
||||
@@ -182,7 +182,7 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapTreeNode& node, uint32 seq) : SHAMapN
|
||||
memcpy(mHashes, node.mHashes, sizeof(mHashes));
|
||||
}
|
||||
|
||||
SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& node, SHAMapItem::pointer item, TNType type, uint32 seq) :
|
||||
SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& node, const SHAMapItem::pointer& item, TNType type, uint32 seq) :
|
||||
SHAMapNode(node), mItem(item), mSeq(seq), mType(type), mFullBelow(true)
|
||||
{
|
||||
assert(item->peekData().size() >= 12);
|
||||
@@ -429,7 +429,7 @@ void SHAMapTreeNode::addRaw(Serializer& s, SHANodeFormat format)
|
||||
assert(false);
|
||||
}
|
||||
|
||||
bool SHAMapTreeNode::setItem(SHAMapItem::pointer& i, TNType type)
|
||||
bool SHAMapTreeNode::setItem(const SHAMapItem::pointer& i, TNType type)
|
||||
{
|
||||
uint256 hash = getNodeHash();
|
||||
mType = type;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "SerializedTransaction.h"
|
||||
#include "Log.h"
|
||||
|
||||
Transaction::Transaction(const SerializedTransaction::pointer sit, bool bValidate)
|
||||
Transaction::Transaction(const SerializedTransaction::pointer& sit, bool bValidate)
|
||||
: mInLedger(0), mStatus(INVALID), mTransaction(sit)
|
||||
{
|
||||
try
|
||||
@@ -584,7 +584,7 @@ void Transaction::setStatus(TransStatus ts, uint32 lseq)
|
||||
mInLedger = lseq;
|
||||
}
|
||||
|
||||
void Transaction::saveTransaction(Transaction::pointer txn)
|
||||
void Transaction::saveTransaction(const Transaction::pointer& txn)
|
||||
{
|
||||
txn->save();
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ private:
|
||||
const std::vector<unsigned char>& vucSignature);
|
||||
|
||||
public:
|
||||
Transaction(const SerializedTransaction::pointer st, bool bValidate);
|
||||
Transaction(const SerializedTransaction::pointer& st, bool bValidate);
|
||||
|
||||
static Transaction::pointer sharedTransaction(const std::vector<unsigned char>&vucTransaction, bool bValidate);
|
||||
|
||||
@@ -288,7 +288,7 @@ public:
|
||||
void setLedger(uint32 ledger) { mInLedger = ledger; }
|
||||
|
||||
// database functions
|
||||
static void saveTransaction(Transaction::pointer);
|
||||
static void saveTransaction(const Transaction::pointer&);
|
||||
bool save();
|
||||
static Transaction::pointer load(const uint256& id);
|
||||
static Transaction::pointer findFrom(const NewcoinAddress& fromID, uint32 seq);
|
||||
|
||||
Reference in New Issue
Block a user