diff --git a/src/cpp/ripple/SerializedObject.cpp b/src/cpp/ripple/SerializedObject.cpp index 2179d5d64..4b644847c 100644 --- a/src/cpp/ripple/SerializedObject.cpp +++ b/src/cpp/ripple/SerializedObject.cpp @@ -639,38 +639,40 @@ std::vector STObject::getFieldVL(SField::ref field) const return cf->getValue(); } -static const STAmount defaultAmount; const STAmount& STObject::getFieldAmount(SField::ref field) const { + static STAmount empty; const SerializedType* rf = peekAtPField(field); if (!rf) throw std::runtime_error("Field not found"); SerializedTypeID id = rf->getSType(); if (id == STI_NOTPRESENT) - return defaultAmount; // optional field not present + return empty; // optional field not present const STAmount *cf = dynamic_cast(rf); if (!cf) throw std::runtime_error("Wrong field type"); return *cf; } -STPathSet STObject::getFieldPathSet(SField::ref field) const +const STPathSet& STObject::getFieldPathSet(SField::ref field) const { + static STPathSet empty; const SerializedType* rf = peekAtPField(field); if (!rf) throw std::runtime_error("Field not found"); SerializedTypeID id = rf->getSType(); - if (id == STI_NOTPRESENT) return STPathSet(); // optional field not present + if (id == STI_NOTPRESENT) return empty; // optional field not present const STPathSet *cf = dynamic_cast(rf); if (!cf) throw std::runtime_error("Wrong field type"); return *cf; } -STVector256 STObject::getFieldV256(SField::ref field) const +const STVector256& STObject::getFieldV256(SField::ref field) const { + static STVector256 empty; const SerializedType* rf = peekAtPField(field); if (!rf) throw std::runtime_error("Field not found"); SerializedTypeID id = rf->getSType(); - if (id == STI_NOTPRESENT) return STVector256(); // optional field not present + if (id == STI_NOTPRESENT) return empty; // optional field not present const STVector256 *cf = dynamic_cast(rf); if (!cf) throw std::runtime_error("Wrong field type"); return *cf; diff --git a/src/cpp/ripple/SerializedObject.h b/src/cpp/ripple/SerializedObject.h index 97ab764f3..c1a7fa35e 100644 --- a/src/cpp/ripple/SerializedObject.h +++ b/src/cpp/ripple/SerializedObject.h @@ -131,8 +131,8 @@ public: uint160 getFieldAccount160(SField::ref field) const; std::vector getFieldVL(SField::ref field) const; const STAmount& getFieldAmount(SField::ref field) const; - STPathSet getFieldPathSet(SField::ref field) const; - STVector256 getFieldV256(SField::ref field) const; + const STPathSet& getFieldPathSet(SField::ref field) const; + const STVector256& getFieldV256(SField::ref field) const; void setFieldU8(SField::ref field, unsigned char); void setFieldU16(SField::ref field, uint16);