From 8d7a2cd8d7d73826dc172235aa74b042224646d8 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 5 Mar 2013 09:54:57 -0800 Subject: [PATCH] Cleanups. --- src/cpp/ripple/SerializedTypes.cpp | 40 ++++++------------------------ src/cpp/ripple/SerializedTypes.h | 13 ++++++---- 2 files changed, 15 insertions(+), 38 deletions(-) diff --git a/src/cpp/ripple/SerializedTypes.cpp b/src/cpp/ripple/SerializedTypes.cpp index f3356a996e..3b5b752290 100644 --- a/src/cpp/ripple/SerializedTypes.cpp +++ b/src/cpp/ripple/SerializedTypes.cpp @@ -421,41 +421,15 @@ bool STPathSet::isEquivalent(const SerializedType& t) const bool STPath::hasSeen(const uint160 &uAccountId, const uint160& uCurrencyID, const uint160& uIssuerID) { - for (int i = 0; i < mPath.size(); ++i) { - STPathElement ele = getElement(i); - - if (ele.getAccountID() == uAccountId - && ele.getCurrency() == uCurrencyID - && ele.getIssuerID() == uIssuerID) - return true; - } - - return false; -} - -int STPath::getSerializeSize() const -{ - int iBytes = 0; - - BOOST_FOREACH(const STPathElement& speElement, mPath) + for (int i = 0; i < mPath.size(); ++i) { - int iType = speElement.getNodeType(); - - iBytes += 1; // mType - - if (iType & STPathElement::typeAccount) - iBytes += 160/8; - - if (iType & STPathElement::typeCurrency) - iBytes += 160/8; - - if (iType & STPathElement::typeIssuer) - iBytes += 160/8; + const STPathElement& ele = getElement(i); + if (ele.getAccountID() == uAccountId + && ele.getCurrency() == uCurrencyID + && ele.getIssuerID() == uIssuerID) + return true; } - - iBytes += 1; // typeBoundary | typeEnd - - return iBytes; + return false; } Json::Value STPath::getJson(int) const diff --git a/src/cpp/ripple/SerializedTypes.h b/src/cpp/ripple/SerializedTypes.h index d501ab4aae..9a75bfde20 100644 --- a/src/cpp/ripple/SerializedTypes.h +++ b/src/cpp/ripple/SerializedTypes.h @@ -34,10 +34,14 @@ enum PathFlags PF_ISSUE = 0x80, }; -#define CURRENCY_XRP uint160(0) -#define CURRENCY_ONE uint160(1) // Used as a place holder -#define ACCOUNT_XRP uint160(0) -#define ACCOUNT_ONE uint160(1) // Used as a place holder +static const uint160 u160_zero(0), u160_one(1); +static inline const uint160& get_u160_zero() { return u160_zero; } +static inline const uint160& get_u160_one() { return u160_one; } + +#define CURRENCY_XRP get_u160_zero() +#define CURRENCY_ONE get_u160_one() // Used as a place holder +#define ACCOUNT_XRP get_u160_zero() +#define ACCOUNT_ONE get_u160_one() // Used as a place holder DEFINE_INSTANCE(SerializedValue); @@ -685,7 +689,6 @@ public: void addElement(const STPathElement &e) { mPath.push_back(e); } void clear() { mPath.clear(); } bool hasSeen(const uint160 &uAccountId, const uint160& uCurrencyID, const uint160& uIssuerID); - int getSerializeSize() const; // std::string getText() const; Json::Value getJson(int) const;