mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
STVar: optimized storage for STObject (RIPD-825):
This introduces the STVar container, capable of holding any STBase-derived class and implementing a "small string" optimization. STObject is changed to store std::vector<STVar> instead of boost::ptr_vector<STBase>. This eliminates a significant number of needless dynamic memory allocations and deallocations during transaction processing when ledger entries are deserialized. It comes at the expense of larger overall storage requirements for STObject.
This commit is contained in:
@@ -25,31 +25,22 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
std::unique_ptr<STBase>
|
||||
STVector256::deserialize (SerialIter& sit, SField::ref name)
|
||||
STVector256::STVector256(SerialIter& sit, SField::ref name)
|
||||
: STBase(name)
|
||||
{
|
||||
auto vec = std::make_unique<STVector256> (name);
|
||||
|
||||
Blob data = sit.getVL ();
|
||||
|
||||
auto const count = data.size () / (256 / 8);
|
||||
|
||||
vec->mValue.reserve (count);
|
||||
|
||||
mValue.reserve (count);
|
||||
Blob::iterator begin = data.begin ();
|
||||
unsigned int uStart = 0;
|
||||
|
||||
for (unsigned int i = 0; i != count; i++)
|
||||
{
|
||||
unsigned int uEnd = uStart + (256 / 8);
|
||||
|
||||
// This next line could be optimized to construct a default uint256
|
||||
// in the vector and then copy into it
|
||||
vec->mValue.push_back (uint256 (Blob (begin + uStart, begin + uEnd)));
|
||||
unsigned int uEnd = uStart + (256 / 8);
|
||||
// This next line could be optimized to construct a default
|
||||
// uint256 in the vector and then copy into it
|
||||
mValue.push_back (uint256 (Blob (begin + uStart, begin + uEnd)));
|
||||
uStart = uEnd;
|
||||
}
|
||||
|
||||
return std::move (vec);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user