mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Avoid a whole lot of extraneous allocate/copy/free cycles when
serialized objects are constructed.
This commit is contained in:
@@ -22,7 +22,7 @@ SerializedLedgerEntry::SerializedLedgerEntry(const Serializer& s, const uint256&
|
||||
if (mFormat == NULL) throw std::runtime_error("invalid ledger entry type");
|
||||
mType = mFormat->t_type;
|
||||
mVersion.setValue(type);
|
||||
mObject = STObject(mFormat->elements, sit);
|
||||
mObject.set(mFormat->elements, sit);
|
||||
}
|
||||
|
||||
SerializedLedgerEntry::SerializedLedgerEntry(LedgerEntryType type) : SerializedType("LedgerEntry"), mType(type)
|
||||
@@ -30,7 +30,7 @@ SerializedLedgerEntry::SerializedLedgerEntry(LedgerEntryType type) : SerializedT
|
||||
mFormat = getLgrFormat(type);
|
||||
if (mFormat == NULL) throw std::runtime_error("invalid ledger entry type");
|
||||
mVersion.setValue(static_cast<uint16>(mFormat->t_type));
|
||||
mObject = STObject(mFormat->elements);
|
||||
mObject.set(mFormat->elements);
|
||||
}
|
||||
|
||||
std::string SerializedLedgerEntry::getFullText() const
|
||||
|
||||
@@ -65,7 +65,13 @@ std::auto_ptr<SerializedType> STObject::makeDeserializedObject(SerializedTypeID
|
||||
return STUInt64::deserialize(sit, name);
|
||||
|
||||
case STI_AMOUNT:
|
||||
return STAmount::deserialize(sit, name);
|
||||
{
|
||||
std::cerr << "Deserializing " << name << std::endl;
|
||||
std::auto_ptr<SerializedType> ptr = STAmount::deserialize(sit, name);
|
||||
assert(!dynamic_cast<STAmount*>(&*ptr)->isZero());
|
||||
std::cerr << "Got: " << ptr->getText() << std::endl;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
case STI_HASH128:
|
||||
return STHash128::deserialize(sit, name);
|
||||
@@ -90,8 +96,12 @@ std::auto_ptr<SerializedType> STObject::makeDeserializedObject(SerializedTypeID
|
||||
}
|
||||
}
|
||||
|
||||
STObject::STObject(SOElement* elem, const char *name) : SerializedType(name), mFlagIdx(-1)
|
||||
void STObject::set(SOElement* elem)
|
||||
{
|
||||
mData.empty();
|
||||
mType.empty();
|
||||
mFlagIdx = -1;
|
||||
|
||||
while (elem->e_id != STI_DONE)
|
||||
{
|
||||
if (elem->e_type == SOE_FLAGS) mFlagIdx = mType.size();
|
||||
@@ -104,8 +114,17 @@ STObject::STObject(SOElement* elem, const char *name) : SerializedType(name), mF
|
||||
}
|
||||
}
|
||||
|
||||
STObject::STObject(SOElement* elem, SerializerIterator& sit, const char *name) : SerializedType(name), mFlagIdx(-1)
|
||||
STObject::STObject(SOElement* elem, const char *name) : SerializedType(name)
|
||||
{
|
||||
set(elem);
|
||||
}
|
||||
|
||||
void STObject::set(SOElement* elem, SerializerIterator& sit)
|
||||
{
|
||||
mData.empty();
|
||||
mType.empty();
|
||||
mFlagIdx = -1;
|
||||
|
||||
int flags = -1;
|
||||
while (elem->e_id != STI_DONE)
|
||||
{
|
||||
@@ -142,6 +161,11 @@ STObject::STObject(SOElement* elem, SerializerIterator& sit, const char *name) :
|
||||
}
|
||||
}
|
||||
|
||||
STObject::STObject(SOElement* elem, SerializerIterator& sit, const char *name) : SerializedType(name), mFlagIdx(-1)
|
||||
{
|
||||
set(elem, sit);
|
||||
}
|
||||
|
||||
std::string STObject::getFullText() const
|
||||
{
|
||||
std::string ret;
|
||||
|
||||
@@ -95,6 +95,9 @@ public:
|
||||
STObject(SOElement *t, SerializerIterator& u, const char *n = NULL);
|
||||
virtual ~STObject() { ; }
|
||||
|
||||
void set(SOElement *t);
|
||||
void set(SOElement *t, SerializerIterator& u);
|
||||
|
||||
int getLength() const;
|
||||
SerializedTypeID getSType() const { return STI_OBJECT; }
|
||||
virtual bool isEquivalent(const SerializedType& t) const;
|
||||
|
||||
Reference in New Issue
Block a user