Large speed up of getField* functions on non-free objects such as transactions and ledger nodes.

This commit is contained in:
JoelKatz
2013-02-28 23:52:53 -08:00
parent fca5683d31
commit 7a9037d1ca
9 changed files with 83 additions and 66 deletions

View File

@@ -18,32 +18,44 @@ DEFINE_INSTANCE(SerializedArray);
class SOElement
{ // An element in the description of a serialized object
public:
typedef SOElement const * ref; // used to point to one element
SField::ref e_field;
const SOE_Flags flags;
SField::ref e_field;
const SOE_Flags flags;
SOElement(SField::ref fi, SOE_Flags fl) : e_field(fi), flags(fl) { ; }
};
SOElement(SField::ref fi, SOE_Flags fl) : e_field(fi), flags(fl) { ; }
class SOTemplate
{
protected:
std::vector<const SOElement*> mTypes;
std::map<int, int> mMap; // field code -> index
public:
SOTemplate() { ; }
const std::vector<const SOElement*>& peek() const { return mTypes; }
void push_back(const SOElement& r);
int getIndex(SField::ref) const;
};
class STObject : public SerializedType, private IS_INSTANCE(SerializedObject)
{
protected:
boost::ptr_vector<SerializedType> mData;
std::vector<SOElement::ref> mType;
const SOTemplate* mType;
STObject* duplicate() const { return new STObject(*this); }
STObject(SField::ref name, boost::ptr_vector<SerializedType>& data) : SerializedType(name) { mData.swap(data); }
STObject(SField::ref name, boost::ptr_vector<SerializedType>& data) : SerializedType(name), mType(NULL)
{ mData.swap(data); }
public:
STObject() { ; }
STObject() : mType(NULL) { ; }
STObject(SField::ref name) : SerializedType(name) { ; }
STObject(SField::ref name) : SerializedType(name), mType(NULL) { ; }
STObject(const std::vector<SOElement::ref>& type, SField::ref name) : SerializedType(name)
STObject(const SOTemplate& type, SField::ref name) : SerializedType(name)
{ set(type); }
STObject(const std::vector<SOElement::ref>& type, SerializerIterator& sit, SField::ref name) : SerializedType(name)
STObject(const SOTemplate& type, SerializerIterator& sit, SField::ref name) : SerializedType(name)
{ set(sit); setType(type); }
std::auto_ptr<STObject> oClone() const { return std::auto_ptr<STObject>(new STObject(*this)); }
@@ -54,12 +66,12 @@ public:
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name);
bool setType(const std::vector<SOElement::ref>& type);
bool setType(const SOTemplate& type);
bool isValidForType();
bool isFieldAllowed(SField::ref);
bool isFree() const { return mType.empty(); }
bool isFree() const { return mType == NULL; }
void set(const std::vector<SOElement::ref>&);
void set(const SOTemplate&);
bool set(SerializerIterator& u, int depth = 0);
virtual SerializedTypeID getSType() const { return STI_OBJECT; }