From 786575c3deb269e5e7123adaa1d266859af7a2e8 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 5 Feb 2018 16:02:44 -0800 Subject: [PATCH] a little bit of cleanup and minor opt --- src/factory/FieldCreateFactory.cpp | 9 ++++----- src/pv/pvIntrospect.h | 18 +++++++++--------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/factory/FieldCreateFactory.cpp b/src/factory/FieldCreateFactory.cpp index b80eed0..1104a65 100644 --- a/src/factory/FieldCreateFactory.cpp +++ b/src/factory/FieldCreateFactory.cpp @@ -460,11 +460,10 @@ string Structure::getID() const } FieldConstPtr Structure::getField(string const & fieldName) const { - size_t numberFields = fields.size(); - for(size_t i=0; i std::tr1::shared_ptr getField(std::string const &fieldName) const { - FieldConstPtr field = getField(fieldName); - if (field.get()) + FieldConstPtr field(getField(fieldName)); + if (field) return std::tr1::dynamic_pointer_cast(field); else return std::tr1::shared_ptr(); @@ -695,13 +695,13 @@ public: * @return The introspection interface. * This will hold a null pointer if the field is not in the structure. */ - FieldConstPtr getField(std::size_t index) const {return fields.at(index);} + const FieldConstPtr& getField(std::size_t index) const {return fields.at(index);} template std::tr1::shared_ptr getField(std::size_t index) const { - FieldConstPtr field = getField(index); - if (field.get()) + const FieldConstPtr& field(getField(index)); + if (field) return std::tr1::dynamic_pointer_cast(field); else return std::tr1::shared_ptr(); @@ -728,7 +728,7 @@ public: * @param fieldIndex The index of the desired field. * @return The fieldName. */ - std::string getFieldName(std::size_t fieldIndex) const {return fieldNames.at(fieldIndex);} + const std::string& getFieldName(std::size_t fieldIndex) const {return fieldNames.at(fieldIndex);} virtual std::string getID() const; @@ -804,7 +804,7 @@ public: std::tr1::shared_ptr getField(std::string const &fieldName) const { FieldConstPtr field = getField(fieldName); - if (field.get()) + if (field) return std::tr1::dynamic_pointer_cast(field); else return std::tr1::shared_ptr(); @@ -822,7 +822,7 @@ public: std::tr1::shared_ptr getField(std::size_t index) const { FieldConstPtr field = getField(index); - if (field.get()) + if (field) return std::tr1::dynamic_pointer_cast(field); else return std::tr1::shared_ptr();