From 8a1033caad1e10761b42f8aaa9c632858123ce34 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 17 Dec 2012 20:31:26 -0800 Subject: [PATCH] Second round of removing extraneous copy constructor and destructor calls. --- src/cpp/ripple/ConnectionPool.cpp | 2 +- src/cpp/ripple/LedgerFormats.h | 2 +- src/cpp/ripple/NetworkOPs.cpp | 2 +- src/cpp/ripple/OrderBook.h | 1 + src/cpp/ripple/OrderBookDB.cpp | 2 +- src/cpp/ripple/Pathfinder.cpp | 14 +++++++------- src/cpp/ripple/Pathfinder.h | 1 + src/cpp/ripple/RPCHandler.cpp | 4 ++-- src/cpp/ripple/SerializedObject.cpp | 14 +++++++------- src/cpp/ripple/SerializedObject.h | 14 +++++++------- src/cpp/ripple/SerializedValidation.cpp | 2 +- src/cpp/ripple/TransactionFormats.h | 2 +- src/cpp/ripple/UniqueNodeList.cpp | 12 ++++++------ 13 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/cpp/ripple/ConnectionPool.cpp b/src/cpp/ripple/ConnectionPool.cpp index fad45ca0f1..1c71b28b96 100644 --- a/src/cpp/ripple/ConnectionPool.cpp +++ b/src/cpp/ripple/ConnectionPool.cpp @@ -365,7 +365,7 @@ Json::Value ConnectionPool::getPeersJson() Json::Value ret(Json::arrayValue); std::vector vppPeers = getPeerVector(); - BOOST_FOREACH(Peer::pointer peer, vppPeers) + BOOST_FOREACH(Peer::ref peer, vppPeers) { ret.append(peer->getJson()); } diff --git a/src/cpp/ripple/LedgerFormats.h b/src/cpp/ripple/LedgerFormats.h index 5f16c63f4f..90ab9cf6b6 100644 --- a/src/cpp/ripple/LedgerFormats.h +++ b/src/cpp/ripple/LedgerFormats.h @@ -48,7 +48,7 @@ class LedgerEntryFormat public: std::string t_name; LedgerEntryType t_type; - std::vector elements; + std::vector elements; static std::map byType; static std::map byName; diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index e6a4c58338..1488ba346b 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -571,7 +571,7 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector& peerLis boost::unordered_map current = theApp->getValidations().getCurrentValidations(closedLedger); typedef std::map::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; diff --git a/src/cpp/ripple/OrderBook.h b/src/cpp/ripple/OrderBook.h index e143589f48..7042bb5fe5 100644 --- a/src/cpp/ripple/OrderBook.h +++ b/src/cpp/ripple/OrderBook.h @@ -16,6 +16,7 @@ class OrderBook OrderBook(SerializedLedgerEntry::pointer ledgerEntry); // For accounts in a ledger public: typedef boost::shared_ptr pointer; + typedef const boost::shared_ptr& 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 diff --git a/src/cpp/ripple/OrderBookDB.cpp b/src/cpp/ripple/OrderBookDB.cpp index ca06acd9b5..192cab703b 100644 --- a/src/cpp/ripple/OrderBookDB.cpp +++ b/src/cpp/ripple/OrderBookDB.cpp @@ -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) { diff --git a/src/cpp/ripple/Pathfinder.cpp b/src/cpp/ripple/Pathfinder.cpp index 0f772bf62e..acce67ae65 100644 --- a/src/cpp/ripple/Pathfinder.cpp +++ b/src/cpp/ripple/Pathfinder.cpp @@ -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 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)); diff --git a/src/cpp/ripple/Pathfinder.h b/src/cpp/ripple/Pathfinder.h index 27f8d4480a..b0cf3ec136 100644 --- a/src/cpp/ripple/Pathfinder.h +++ b/src/cpp/ripple/Pathfinder.h @@ -18,6 +18,7 @@ class PathOption { public: typedef boost::shared_ptr pointer; + typedef const boost::shared_ptr& ref; STPath mPath; bool mCorrectCurrency; // for the sorting diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index f560688b23..30844575a9 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -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(); diff --git a/src/cpp/ripple/SerializedObject.cpp b/src/cpp/ripple/SerializedObject.cpp index 2e87706e1a..bc20aaf1a7 100644 --- a/src/cpp/ripple/SerializedObject.cpp +++ b/src/cpp/ripple/SerializedObject.cpp @@ -130,12 +130,12 @@ std::auto_ptr STObject::makeDeserializedObject(SerializedTypeID } } -void STObject::set(const std::vector& type) +void STObject::set(const std::vector& 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& type) } } -bool STObject::setType(const std::vector &type) +bool STObject::setType(const std::vector &type) { boost::ptr_vector 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::iterator it = mData.begin(); it != mData.end(); ++it) @@ -200,7 +200,7 @@ bool STObject::setType(const std::vector &type) bool STObject::isValidForType() { boost::ptr_vector::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 elements; + std::vector 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)); diff --git a/src/cpp/ripple/SerializedObject.h b/src/cpp/ripple/SerializedObject.h index 99207fb72e..aeab2e3513 100644 --- a/src/cpp/ripple/SerializedObject.h +++ b/src/cpp/ripple/SerializedObject.h @@ -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 mData; - std::vector mType; + boost::ptr_vector mData; + std::vector mType; STObject* duplicate() const { return new STObject(*this); } STObject(SField::ref name, boost::ptr_vector& data) : SerializedType(name) { mData.swap(data); } @@ -40,10 +40,10 @@ public: STObject(SField::ref name) : SerializedType(name) { ; } - STObject(const std::vector& type, SField::ref name) : SerializedType(name) + STObject(const std::vector& type, SField::ref name) : SerializedType(name) { set(type); } - STObject(const std::vector& type, SerializerIterator& sit, SField::ref name) : SerializedType(name) + STObject(const std::vector& type, SerializerIterator& sit, SField::ref name) : SerializedType(name) { set(sit); setType(type); } std::auto_ptr oClone() const { return std::auto_ptr(new STObject(*this)); } @@ -54,12 +54,12 @@ public: static std::auto_ptr deserialize(SerializerIterator& sit, SField::ref name); - bool setType(const std::vector& type); + bool setType(const std::vector& type); bool isValidForType(); bool isFieldAllowed(SField::ref); bool isFree() const { return mType.empty(); } - void set(const std::vector&); + void set(const std::vector&); bool set(SerializerIterator& u, int depth = 0); virtual SerializedTypeID getSType() const { return STI_OBJECT; } diff --git a/src/cpp/ripple/SerializedValidation.cpp b/src/cpp/ripple/SerializedValidation.cpp index c580e1a266..3f502d447c 100644 --- a/src/cpp/ripple/SerializedValidation.cpp +++ b/src/cpp/ripple/SerializedValidation.cpp @@ -6,7 +6,7 @@ DECLARE_INSTANCE(SerializedValidation); -std::vector sValidationFormat; +std::vector sValidationFormat; static bool SVFInit() { diff --git a/src/cpp/ripple/TransactionFormats.h b/src/cpp/ripple/TransactionFormats.h index 778da0405b..a67eb05c85 100644 --- a/src/cpp/ripple/TransactionFormats.h +++ b/src/cpp/ripple/TransactionFormats.h @@ -28,7 +28,7 @@ class TransactionFormat public: std::string t_name; TransactionType t_type; - std::vector elements; + std::vector elements; static std::map byType; static std::map byName; diff --git a/src/cpp/ripple/UniqueNodeList.cpp b/src/cpp/ripple/UniqueNodeList.cpp index df37f6d4df..6e5ecda26c 100644 --- a/src/cpp/ripple/UniqueNodeList.cpp +++ b/src/cpp/ripple/UniqueNodeList.cpp @@ -468,8 +468,8 @@ void UniqueNodeList::scoreCompute() // map of pair :: score epScore umScore; - std::pair< std::string, int> vc; - BOOST_FOREACH(vc, umValidators) + typedef boost::unordered_map::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, 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;