From: mpv Date: Thu, 24 Jul 2014 06:46:06 +0000 (+0400) Subject: Optimization: arguments in Data methods by reference X-Git-Tag: V_0.4.4~154^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e5932a539d6ff1bdeab1e588603448e7810a5958;p=modules%2Fshaper.git Optimization: arguments in Data methods by reference --- diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index e08e565bd..2cf5b1b86 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -37,7 +37,7 @@ string Model_Data::name() return ""; // not defined } -void Model_Data::setName(string theName) +void Model_Data::setName(const string& theName) { bool isModified = false; Handle(TDataStd_Name) aName; @@ -56,7 +56,7 @@ void Model_Data::setName(string theName) }*/ } -void Model_Data::addAttribute(string theID, string theAttrType) +void Model_Data::addAttribute(const string& theID, const string theAttrType) { TDF_Label anAttrLab = myLab.FindChild(myAttrs.size() + 1); ModelAPI_Attribute* anAttr = 0; @@ -88,7 +88,7 @@ void Model_Data::addAttribute(string theID, string theAttrType) } } -boost::shared_ptr Model_Data::docRef(const string theID) +boost::shared_ptr Model_Data::docRef(const string& theID) { map >::iterator aFound = myAttrs.find(theID); if (aFound == myAttrs.end()) { @@ -103,7 +103,7 @@ boost::shared_ptr Model_Data::docRef(const string theI return aRes; } -boost::shared_ptr Model_Data::real(const string theID) +boost::shared_ptr Model_Data::real(const string& theID) { map >::iterator aFound = myAttrs.find(theID); if (aFound == myAttrs.end()) { @@ -118,7 +118,7 @@ boost::shared_ptr Model_Data::real(const string theID) return aRes; } -boost::shared_ptr Model_Data::boolean(const std::string theID) +boost::shared_ptr Model_Data::boolean(const std::string& theID) { map >::iterator aFound = myAttrs.find(theID); if (aFound == myAttrs.end()) { @@ -133,7 +133,7 @@ boost::shared_ptr Model_Data::boolean(const std::stri return aRes; } -boost::shared_ptr Model_Data::reference(const string theID) +boost::shared_ptr Model_Data::reference(const string& theID) { map >::iterator aFound = myAttrs.find(theID); if (aFound == myAttrs.end()) { @@ -148,7 +148,7 @@ boost::shared_ptr Model_Data::reference(const strin return aRes; } -boost::shared_ptr Model_Data::refattr(const string theID) +boost::shared_ptr Model_Data::refattr(const string& theID) { map >::iterator aFound = myAttrs.find(theID); if (aFound == myAttrs.end()) { @@ -163,7 +163,7 @@ boost::shared_ptr Model_Data::refattr(const string th return aRes; } -boost::shared_ptr Model_Data::reflist(const string theID) +boost::shared_ptr Model_Data::reflist(const string& theID) { map >::iterator aFound = myAttrs.find(theID); if (aFound == myAttrs.end()) { @@ -178,7 +178,7 @@ boost::shared_ptr Model_Data::reflist(const string th return aRes; } -boost::shared_ptr Model_Data::attribute(const std::string theID) +boost::shared_ptr Model_Data::attribute(const std::string& theID) { boost::shared_ptr aResult; if (myAttrs.find(theID) == myAttrs.end()) // no such attribute @@ -186,7 +186,7 @@ boost::shared_ptr Model_Data::attribute(const std::string th return myAttrs[theID]; } -const string& Model_Data::id(const boost::shared_ptr theAttr) +const string& Model_Data::id(const boost::shared_ptr& theAttr) { map >::iterator anAttr = myAttrs.begin(); for(; anAttr != myAttrs.end(); anAttr++) { @@ -197,7 +197,7 @@ const string& Model_Data::id(const boost::shared_ptr theAttr return anEmpty; } -bool Model_Data::isEqual(const boost::shared_ptr theData) +bool Model_Data::isEqual(const boost::shared_ptr& theData) { boost::shared_ptr aData = boost::dynamic_pointer_cast(theData); if (aData) @@ -210,7 +210,7 @@ bool Model_Data::isValid() return !myLab.IsNull() && myLab.HasAttribute(); } -list > Model_Data::attributes(const string theType) +list > Model_Data::attributes(const string& theType) { list > aResult; map >::iterator anAttrsIter = myAttrs.begin(); diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index c63bce476..7faa34331 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -43,36 +43,36 @@ public: /// Returns the name of the feature visible by the user in the object browser MODEL_EXPORT virtual std::string name(); /// Defines the name of the feature visible by the user in the object browser - MODEL_EXPORT virtual void setName(std::string theName); + MODEL_EXPORT virtual void setName(const std::string& theName); /// Returns the attribute that references to another document - MODEL_EXPORT virtual boost::shared_ptr docRef(const std::string theID); + MODEL_EXPORT virtual boost::shared_ptr docRef(const std::string& theID); /// Returns the attribute that contains real value with double precision - MODEL_EXPORT virtual boost::shared_ptr real(const std::string theID); + MODEL_EXPORT virtual boost::shared_ptr real(const std::string& theID); /// Returns the attribute that contains reference to a feature MODEL_EXPORT virtual boost::shared_ptr - reference(const std::string theID); + reference(const std::string& theID); /// Returns the attribute that contains reference to an attribute of a feature MODEL_EXPORT virtual boost::shared_ptr - refattr(const std::string theID); + refattr(const std::string& theID); /// Returns the attribute that contains list of references to features MODEL_EXPORT virtual boost::shared_ptr - reflist(const std::string theID); + reflist(const std::string& theID); /// Returns the attribute that contains boolean value MODEL_EXPORT virtual boost::shared_ptr - boolean(const std::string theID); + boolean(const std::string& theID); /// Returns the generic attribute by identifier /// \param theID identifier of the attribute - MODEL_EXPORT virtual boost::shared_ptr attribute(const std::string theID); + MODEL_EXPORT virtual boost::shared_ptr attribute(const std::string& theID); /// Returns all attributes ofthe feature of the given type /// or all attributes if "theType" is empty MODEL_EXPORT virtual std::list > - attributes(const std::string theType); + attributes(const std::string& theType); /// Identifier by the id (not fast, iteration by map) /// \param theAttr attribute already created in this data - MODEL_EXPORT virtual const std::string& id(const boost::shared_ptr theAttr); + MODEL_EXPORT virtual const std::string& id(const boost::shared_ptr& theAttr); /// Returns true if data belongs to same features - MODEL_EXPORT virtual bool isEqual(const boost::shared_ptr theData); + MODEL_EXPORT virtual bool isEqual(const boost::shared_ptr& theData); /// Returns true if it is correctly connected t othe data model MODEL_EXPORT virtual bool isValid(); @@ -83,7 +83,7 @@ public: /// for each attribute of the object /// \param theID identifier of the attribute that can be referenced by this ID later /// \param theAttrType type of the created attribute (received from the type method) - MODEL_EXPORT virtual void addAttribute(std::string theID, std::string theAttrType); + MODEL_EXPORT virtual void addAttribute(const std::string& theID, const std::string theAttrType); /// Useful method for "set" methods of the attributes: sends an UPDATE event and /// makes attribute initialized diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index eea1d1ae8..3a414e1ea 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -34,33 +34,33 @@ public: virtual std::string name() = 0; /// Defines the name of the feature visible by the user in the object browser - virtual void setName(std::string theName) = 0; + virtual void setName(const std::string& theName) = 0; /// Returns the attribute that references to another document - virtual boost::shared_ptr docRef(const std::string theID) = 0; + virtual boost::shared_ptr docRef(const std::string& theID) = 0; /// Returns the attribute that contains real value with double precision - virtual boost::shared_ptr real(const std::string theID) = 0; + virtual boost::shared_ptr real(const std::string& theID) = 0; /// Returns the attribute that contains reference to a feature - virtual boost::shared_ptr reference(const std::string theID) = 0; + virtual boost::shared_ptr reference(const std::string& theID) = 0; /// Returns the attribute that contains reference to an attribute of a feature - virtual boost::shared_ptr refattr(const std::string theID) = 0; + virtual boost::shared_ptr refattr(const std::string& theID) = 0; /// Returns the attribute that contains list of references to features - virtual boost::shared_ptr reflist(const std::string theID) = 0; + virtual boost::shared_ptr reflist(const std::string& theID) = 0; /// Returns the attribute that contains boolean value - virtual boost::shared_ptr boolean(const std::string theID) = 0; + virtual boost::shared_ptr boolean(const std::string& theID) = 0; /// Returns the generic attribute by identifier /// \param theID identifier of the attribute - virtual boost::shared_ptr attribute(const std::string theID) = 0; + virtual boost::shared_ptr attribute(const std::string& theID) = 0; /// Returns all attributes ofthe feature of the given type /// or all attributes if "theType" is empty virtual std::list > - attributes(const std::string theType) = 0; + attributes(const std::string& theType) = 0; /// Identifier by the id (not fast, iteration by map) /// \param theAttr attribute already created in this data - virtual const std::string& id(const boost::shared_ptr theAttr) = 0; + virtual const std::string& id(const boost::shared_ptr& theAttr) = 0; /// Returns true if data belongs to same features - virtual bool isEqual(const boost::shared_ptr theData) = 0; + virtual bool isEqual(const boost::shared_ptr& theData) = 0; /// Returns true if it is correctly connected t othe data model virtual bool isValid() = 0; @@ -68,7 +68,7 @@ public: /// for each attribute of the object /// \param theID identifier of the attribute that can be referenced by this ID later /// \param theAttrType type of the created attribute (received from the type method) - virtual void addAttribute(std::string theID, std::string theAttrType) = 0; + virtual void addAttribute(const std::string& theID, const std::string theAttrType) = 0; /// Useful method for "set" methods of the attributes: sends an UPDATE event and /// makes attribute initialized