0030835: Possible performance improvements in methods TDF_Label::FindAttribute
authormpv <mpv@opencascade.com>
Mon, 29 Jul 2019 14:11:54 +0000 (17:11 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 2 Aug 2019 12:42:54 +0000 (15:42 +0300)
Make attribute iterator work with pointers to attributes, so, creation of handle on each iteration is avoided.

src/TDF/TDF_AttributeIterator.hxx
src/TDF/TDF_Label.cxx
src/TDF/TDF_Label.hxx

index fa8622c..dbc6103 100644 (file)
@@ -61,6 +61,9 @@ public:
   Standard_EXPORT   void Next() ;
   inline   Handle(TDF_Attribute) Value() const;
 
+  //! Provides an access to the internal pointer of the current attribute.
+  //! The method has better performance as not-creating handle.
+  inline const TDF_Attribute* PtrValue() const { return myValue; }
 
 protected:
 
index 838a44b..eba97eb 100644 (file)
@@ -60,8 +60,8 @@ Standard_Boolean TDF_Label::FindAttribute
   if (IsNull()) throw Standard_NullObject("A null Label has no attribute.");
   TDF_AttributeIterator itr (myLabelNode); // Without removed attributes.
   for ( ; itr.More(); itr.Next()) {
-    if (itr.Value()->ID() == anID) {
-      anAttribute = itr.Value();
+    if (itr.PtrValue()->ID() == anID) {
+      anAttribute = itr.PtrValue();
       return Standard_True;
     }
   }
index ab01f01..e4a5be3 100644 (file)
@@ -154,7 +154,7 @@ public:
   template <class T> 
   Standard_Boolean FindAttribute (const Standard_GUID& theID, Handle(T)& theAttr) const
   { 
-    Handle(TDF_Attribute) anAttr = theAttr;
+    Handle(TDF_Attribute) anAttr;
     return FindAttribute (theID, anAttr) && ! (theAttr = Handle(T)::DownCast(anAttr)).IsNull();
   }