From d22c11be1c162c700a75a7e71fe69581e3dc1778 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 17 May 2013 01:40:55 -0700 Subject: [PATCH] Return references. --- src/cpp/ripple/SerializedObject.cpp | 14 ++++++++------ src/cpp/ripple/SerializedObject.h | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/cpp/ripple/SerializedObject.cpp b/src/cpp/ripple/SerializedObject.cpp index 2179d5d642..4b644847c7 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 97ab764f3a..c1a7fa35ec 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);