Second round of removing extraneous copy constructor and destructor calls.

This commit is contained in:
JoelKatz
2012-12-17 20:31:26 -08:00
parent 2a06686b7c
commit 8a1033caad
13 changed files with 37 additions and 35 deletions

View File

@@ -365,7 +365,7 @@ Json::Value ConnectionPool::getPeersJson()
Json::Value ret(Json::arrayValue);
std::vector<Peer::pointer> vppPeers = getPeerVector();
BOOST_FOREACH(Peer::pointer peer, vppPeers)
BOOST_FOREACH(Peer::ref peer, vppPeers)
{
ret.append(peer->getJson());
}

View File

@@ -48,7 +48,7 @@ class LedgerEntryFormat
public:
std::string t_name;
LedgerEntryType t_type;
std::vector<SOElement::ptr> elements;
std::vector<SOElement::ref> elements;
static std::map<int, LedgerEntryFormat*> byType;
static std::map<std::string, LedgerEntryFormat*> byName;

View File

@@ -571,7 +571,7 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerLis
boost::unordered_map<uint256, currentValidationCount> current =
theApp->getValidations().getCurrentValidations(closedLedger);
typedef std::map<uint256, currentValidationCount>::value_type u256_cvc_pair;
BOOST_FOREACH(u256_cvc_pair& it, current)
BOOST_FOREACH(const u256_cvc_pair& it, current)
{
ValidationCount& vc = ledgers[it.first];
vc.trustedValidations += it.second.first;

View File

@@ -16,6 +16,7 @@ class OrderBook
OrderBook(SerializedLedgerEntry::pointer ledgerEntry); // For accounts in a ledger
public:
typedef boost::shared_ptr<OrderBook> pointer;
typedef const boost::shared_ptr<OrderBook>& ref;
// returns NULL if ledgerEntry doesn't point to an order
// if ledgerEntry is an Order it creates the OrderBook this order would live in

View File

@@ -45,7 +45,7 @@ void OrderBookDB::getBooks(const uint160& issuerID, const uint160& currencyID, s
{
if( mIssuerMap.find(issuerID) == mIssuerMap.end() )
{
BOOST_FOREACH(OrderBook::pointer book, mIssuerMap[issuerID])
BOOST_FOREACH(OrderBook::ref book, mIssuerMap[issuerID])
{
if(book->getCurrencyIn()==currencyID)
{

View File

@@ -269,7 +269,7 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
else if (!speEnd.mCurrencyID)
{
// Last element is for XRP continue with qualifying books.
BOOST_FOREACH(OrderBook::pointer book, mOrderBook.getXRPInBooks())
BOOST_FOREACH(OrderBook::ref book, mOrderBook.getXRPInBooks())
{
// XXX Don't allow looping through same order books.
@@ -303,7 +303,7 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
// Create new paths for each outbound account not already in the path.
AccountItems rippleLines(speEnd.mAccountID, mLedger, AccountItem::pointer(new RippleState()));
BOOST_FOREACH(AccountItem::pointer item, rippleLines.getItems())
BOOST_FOREACH(AccountItem::ref item, rippleLines.getItems())
{
RippleState* line=(RippleState*)item.get();
@@ -342,7 +342,7 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
mOrderBook.getBooks(spPath.mCurrentAccount, spPath.mCurrencyID, books);
BOOST_FOREACH(OrderBook::pointer book,books)
BOOST_FOREACH(OrderBook::ref book,books)
{
STPath new_path(spPath);
STPathElement new_ele(uint160(), book->getCurrencyOut(), book->getIssuerOut());
@@ -457,7 +457,7 @@ bool Pathfinder::checkComplete(STPathSet& retPathSet)
if (mCompletePaths.size())
{ // TODO: look through these and pick the most promising
int count=0;
BOOST_FOREACH(PathOption::pointer pathOption,mCompletePaths)
BOOST_FOREACH(PathOption::ref pathOption,mCompletePaths)
{
retPathSet.addPath(pathOption->mPath);
count++;
@@ -480,7 +480,7 @@ void Pathfinder::addOptions(PathOption::pointer tail)
{
if (!tail->mCurrencyID)
{ // source XRP
BOOST_FOREACH(OrderBook::pointer book, mOrderBook.getXRPInBooks())
BOOST_FOREACH(OrderBook::ref book, mOrderBook.getXRPInBooks())
{
PathOption::pointer pathOption(new PathOption(tail));
@@ -495,7 +495,7 @@ void Pathfinder::addOptions(PathOption::pointer tail)
else
{ // ripple
RippleLines rippleLines(tail->mCurrentAccount);
BOOST_FOREACH(RippleState::pointer line,rippleLines.getLines())
BOOST_FOREACH(RippleState::ref line,rippleLines.getLines())
{
// TODO: make sure we can move in the correct direction
STAmount balance=line->getBalance();
@@ -516,7 +516,7 @@ void Pathfinder::addOptions(PathOption::pointer tail)
std::vector<OrderBook::pointer> books;
mOrderBook.getBooks(tail->mCurrentAccount, tail->mCurrencyID, books);
BOOST_FOREACH(OrderBook::pointer book,books)
BOOST_FOREACH(OrderBook::ref book,books)
{
PathOption::pointer pathOption(new PathOption(tail));

View File

@@ -18,6 +18,7 @@ class PathOption
{
public:
typedef boost::shared_ptr<PathOption> pointer;
typedef const boost::shared_ptr<PathOption>& ref;
STPath mPath;
bool mCorrectCurrency; // for the sorting

View File

@@ -564,7 +564,7 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest)
AccountItems rippleLines(raAccount.getAccountID(), lpLedger, AccountItem::pointer(new RippleState()));
BOOST_FOREACH(AccountItem::pointer item, rippleLines.getItems())
BOOST_FOREACH(AccountItem::ref item, rippleLines.getItems())
{
RippleState* line=(RippleState*)item.get();
@@ -633,7 +633,7 @@ Json::Value RPCHandler::doAccountOffers(Json::Value jvRequest)
Json::Value jsonLines(Json::arrayValue);
AccountItems offers(raAccount.getAccountID(), lpLedger, AccountItem::pointer(new Offer()));
BOOST_FOREACH(AccountItem::pointer item, offers.getItems())
BOOST_FOREACH(AccountItem::ref item, offers.getItems())
{
Offer* offer=(Offer*)item.get();

View File

@@ -130,12 +130,12 @@ std::auto_ptr<SerializedType> STObject::makeDeserializedObject(SerializedTypeID
}
}
void STObject::set(const std::vector<SOElement::ptr>& type)
void STObject::set(const std::vector<SOElement::ref>& type)
{
mData.clear();
mType.clear();
BOOST_FOREACH(const SOElement::ptr& elem, type)
BOOST_FOREACH(SOElement::ref elem, type)
{
mType.push_back(elem);
if (elem->flags != SOE_REQUIRED)
@@ -145,13 +145,13 @@ void STObject::set(const std::vector<SOElement::ptr>& type)
}
}
bool STObject::setType(const std::vector<SOElement::ptr> &type)
bool STObject::setType(const std::vector<SOElement::ref> &type)
{
boost::ptr_vector<SerializedType> newData;
bool valid = true;
mType.clear();
BOOST_FOREACH(const SOElement::ptr& elem, type)
BOOST_FOREACH(SOElement::ref elem, type)
{
bool match = false;
for (boost::ptr_vector<SerializedType>::iterator it = mData.begin(); it != mData.end(); ++it)
@@ -200,7 +200,7 @@ bool STObject::setType(const std::vector<SOElement::ptr> &type)
bool STObject::isValidForType()
{
boost::ptr_vector<SerializedType>::iterator it = mData.begin();
BOOST_FOREACH(SOElement::ptr elem, mType)
BOOST_FOREACH(SOElement::ref elem, mType)
{
if (it == mData.end())
return false;
@@ -216,7 +216,7 @@ bool STObject::isFieldAllowed(SField::ref field)
{
if (isFree())
return true;
BOOST_FOREACH(SOElement::ptr elem, mType)
BOOST_FOREACH(SOElement::ref elem, mType)
{ // are any required elemnents missing
if (elem->e_field == field)
return true;
@@ -1242,7 +1242,7 @@ BOOST_AUTO_TEST_CASE( FieldManipulation_test )
SField sfTestU32(STI_UINT32, 255, "TestU32");
SField sfTestObject(STI_OBJECT, 255, "TestObject");
std::vector<SOElement::ptr> elements;
std::vector<SOElement::ref> elements;
elements.push_back(new SOElement(sfFlags, SOE_REQUIRED));
elements.push_back(new SOElement(sfTestVL, SOE_REQUIRED));
elements.push_back(new SOElement(sfTestH256, SOE_OPTIONAL));

View File

@@ -18,7 +18,7 @@ DEFINE_INSTANCE(SerializedArray);
class SOElement
{ // An element in the description of a serialized object
public:
typedef SOElement const * ptr; // used to point to one element
typedef SOElement const * ref; // used to point to one element
SField::ref e_field;
const SOE_Flags flags;
@@ -29,8 +29,8 @@ public:
class STObject : public SerializedType, private IS_INSTANCE(SerializedObject)
{
protected:
boost::ptr_vector<SerializedType> mData;
std::vector<SOElement::ptr> mType;
boost::ptr_vector<SerializedType> mData;
std::vector<SOElement::ref> mType;
STObject* duplicate() const { return new STObject(*this); }
STObject(SField::ref name, boost::ptr_vector<SerializedType>& data) : SerializedType(name) { mData.swap(data); }
@@ -40,10 +40,10 @@ public:
STObject(SField::ref name) : SerializedType(name) { ; }
STObject(const std::vector<SOElement::ptr>& type, SField::ref name) : SerializedType(name)
STObject(const std::vector<SOElement::ref>& type, SField::ref name) : SerializedType(name)
{ set(type); }
STObject(const std::vector<SOElement::ptr>& type, SerializerIterator& sit, SField::ref name) : SerializedType(name)
STObject(const std::vector<SOElement::ref>& type, SerializerIterator& sit, SField::ref name) : SerializedType(name)
{ set(sit); setType(type); }
std::auto_ptr<STObject> oClone() const { return std::auto_ptr<STObject>(new STObject(*this)); }
@@ -54,12 +54,12 @@ public:
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name);
bool setType(const std::vector<SOElement::ptr>& type);
bool setType(const std::vector<SOElement::ref>& type);
bool isValidForType();
bool isFieldAllowed(SField::ref);
bool isFree() const { return mType.empty(); }
void set(const std::vector<SOElement::ptr>&);
void set(const std::vector<SOElement::ref>&);
bool set(SerializerIterator& u, int depth = 0);
virtual SerializedTypeID getSType() const { return STI_OBJECT; }

View File

@@ -6,7 +6,7 @@
DECLARE_INSTANCE(SerializedValidation);
std::vector<SOElement::ptr> sValidationFormat;
std::vector<SOElement::ref> sValidationFormat;
static bool SVFInit()
{

View File

@@ -28,7 +28,7 @@ class TransactionFormat
public:
std::string t_name;
TransactionType t_type;
std::vector<SOElement::ptr> elements;
std::vector<SOElement::ref> elements;
static std::map<int, TransactionFormat*> byType;
static std::map<std::string, TransactionFormat*> byName;

View File

@@ -468,8 +468,8 @@ void UniqueNodeList::scoreCompute()
// map of pair<IP,Port> :: score
epScore umScore;
std::pair< std::string, int> vc;
BOOST_FOREACH(vc, umValidators)
typedef boost::unordered_map<std::string, int>::value_type vcType;
BOOST_FOREACH(vcType& vc, umValidators)
{
std::string strValidator = vc.first;
@@ -506,8 +506,8 @@ void UniqueNodeList::scoreCompute()
vstrValues.reserve(umScore.size());
std::pair< ipPort, score> ipScore;
BOOST_FOREACH(ipScore, umScore)
typedef boost::unordered_map<std::pair< std::string, int>, score>::value_type ipScoreType;
BOOST_FOREACH(ipScoreType& ipScore, umScore)
{
ipPort ipEndpoint = ipScore.first;
std::string strIpPort = str(boost::format("%s %d") % ipEndpoint.first % ipEndpoint.second);
@@ -638,7 +638,7 @@ void UniqueNodeList::processIps(const std::string& strSite, const RippleAddress&
vstrValues.resize(MIN(pmtVecStrIps->size(), REFERRAL_IPS_MAX));
int iValues = 0;
BOOST_FOREACH(std::string strReferral, *pmtVecStrIps)
BOOST_FOREACH(const std::string& strReferral, *pmtVecStrIps)
{
if (iValues == REFERRAL_VALIDATORS_MAX)
break;
@@ -709,7 +709,7 @@ int UniqueNodeList::processValidators(const std::string& strSite, const std::str
vstrValues.reserve(MIN(pmtVecStrValidators->size(), REFERRAL_VALIDATORS_MAX));
BOOST_FOREACH(std::string strReferral, *pmtVecStrValidators)
BOOST_FOREACH(const std::string& strReferral, *pmtVecStrValidators)
{
if (iValues == REFERRAL_VALIDATORS_MAX)
break;