Fix some inefficiecies.

This commit is contained in:
JoelKatz
2013-02-21 10:42:17 -08:00
parent e3b4571831
commit a331d23183
2 changed files with 8 additions and 7 deletions

View File

@@ -282,22 +282,23 @@ STAccount* STAccount::construct(SerializerIterator& u, SField::ref name)
STVector256* STVector256::construct(SerializerIterator& u, SField::ref name) STVector256* STVector256::construct(SerializerIterator& u, SField::ref name)
{ {
std::vector<unsigned char> data = u.getVL(); std::vector<unsigned char> data = u.getVL();
std::vector<uint256> value;
std::auto_ptr<STVector256> vec(new STVector256(name));
int count = data.size() / (256 / 8); int count = data.size() / (256 / 8);
value.reserve(count); vec->mValue.reserve(count);
unsigned int uStart = 0; unsigned int uStart = 0;
for (unsigned int i = 0; i != count; i++) for (unsigned int i = 0; i != count; i++)
{ {
unsigned int uEnd = uStart+(256/8); unsigned int uEnd = uStart+(256/8);
value.push_back(uint256(std::vector<unsigned char>(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<unsigned char>(data.begin()+uStart, data.begin()+uEnd)));
uStart = uEnd; uStart = uEnd;
} }
return new STVector256(name, value); return vec.release();
} }
void STVector256::add(Serializer& s) const void STVector256::add(Serializer& s) const

View File

@@ -176,7 +176,7 @@ protected:
memset(&vchData[0], 0, vchData.size()); memset(&vchData[0], 0, vchData.size());
} }
void SetData(int nVersionIn, std::vector<unsigned char> vchDataIn) void SetData(int nVersionIn, const std::vector<unsigned char>& vchDataIn)
{ {
nVersion = nVersionIn; nVersion = nVersionIn;
vchData = vchDataIn; vchData = vchDataIn;
@@ -186,7 +186,7 @@ protected:
{ {
nVersion = nVersionIn; nVersion = nVersionIn;
vchData.resize(nSize); vchData.resize(nSize);
if (!vchData.empty()) if (nSize)
memcpy(&vchData[0], pdata, nSize); memcpy(&vchData[0], pdata, nSize);
} }