From a331d23183c62ed5d8671ded656305664a11db95 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 21 Feb 2013 10:42:17 -0800 Subject: [PATCH] Fix some inefficiecies. --- src/cpp/ripple/SerializedTypes.cpp | 11 ++++++----- src/cpp/ripple/base58.h | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cpp/ripple/SerializedTypes.cpp b/src/cpp/ripple/SerializedTypes.cpp index 46e599b4f..d7d1327fc 100644 --- a/src/cpp/ripple/SerializedTypes.cpp +++ b/src/cpp/ripple/SerializedTypes.cpp @@ -282,22 +282,23 @@ STAccount* STAccount::construct(SerializerIterator& u, SField::ref name) STVector256* STVector256::construct(SerializerIterator& u, SField::ref name) { std::vector data = u.getVL(); - std::vector value; + + std::auto_ptr vec(new STVector256(name)); int count = data.size() / (256 / 8); - value.reserve(count); + vec->mValue.reserve(count); unsigned int uStart = 0; for (unsigned int i = 0; i != count; i++) { unsigned int uEnd = uStart+(256/8); - value.push_back(uint256(std::vector(data.begin()+uStart, data.begin()+(uStart+32)))); - + // This next line could be optimized to construct a default uint256 in the vector and then copy into it + vec->mValue.push_back(uint256(std::vector(data.begin()+uStart, data.begin()+uEnd))); uStart = uEnd; } - return new STVector256(name, value); + return vec.release(); } void STVector256::add(Serializer& s) const diff --git a/src/cpp/ripple/base58.h b/src/cpp/ripple/base58.h index e2fa1c367..5f08f4871 100644 --- a/src/cpp/ripple/base58.h +++ b/src/cpp/ripple/base58.h @@ -176,7 +176,7 @@ protected: memset(&vchData[0], 0, vchData.size()); } - void SetData(int nVersionIn, std::vector vchDataIn) + void SetData(int nVersionIn, const std::vector& vchDataIn) { nVersion = nVersionIn; vchData = vchDataIn; @@ -186,7 +186,7 @@ protected: { nVersion = nVersionIn; vchData.resize(nSize); - if (!vchData.empty()) + if (nSize) memcpy(&vchData[0], pdata, nSize); }