]> OCCT Git - occt.git/commitdiff
Foundation Classes - Optimize IsKind operation #234
authordpasukhi <dpasukhi@opencascade.com>
Sat, 4 Jan 2025 12:38:42 +0000 (12:38 +0000)
committerdpasukhi <dpasukhi@opencascade.com>
Sat, 4 Jan 2025 15:19:49 +0000 (15:19 +0000)
Refactor Standard_Type::SubType methods for improved clarity and performance

src/Standard/Standard_Type.cxx

index 6321deab29b078fa75bc1b62757f9efc7371624a..875e7c3e5bee52871a308334d09ee38c43944b15 100644 (file)
@@ -31,26 +31,44 @@ Standard_Type::Standard_Type (const std::type_info& theInfo,
   myName(theName),
   mySize(theSize), 
   myParent(theParent)
-{
-}
-
-//============================================================================
+{}
 
-Standard_Boolean Standard_Type::SubType (const Handle(Standard_Type)& theOther) const
+Standard_Boolean Standard_Type::SubType(const Handle(Standard_Type)& theOther) const
 {
-  return ! theOther.IsNull() && (theOther == this || (! myParent.IsNull() && myParent->SubType (theOther)));
+  if (theOther.IsNull())
+  {
+    return false;
+  }
+  const Standard_Type* aTypeIter = this;
+  while (aTypeIter && theOther->mySize <= aTypeIter->mySize)
+  {
+    if (theOther.get() == aTypeIter)
+    {
+      return true;
+    }
+    aTypeIter = aTypeIter->Parent().get();
+  }
+  return false;
 }
 
-//============================================================================
-
-Standard_Boolean Standard_Type::SubType (const Standard_CString theName) const
+Standard_Boolean Standard_Type::SubType(const Standard_CString theName) const
 {
-  return theName != 0 && (IsEqual (myName, theName) || (! myParent.IsNull() && myParent->SubType (theName)));
+  if (!theName)
+  {
+    return false;
+  }
+  const Standard_Type* aTypeIter = this;
+  while (aTypeIter)
+  {
+    if (IsEqual(theName, aTypeIter->Name()))
+    {
+      return true;
+    }
+    aTypeIter = aTypeIter->Parent().get();
+  }
+  return false;
 }
 
-// ------------------------------------------------------------------
-// Print (me; s: in out OStream) returns OStream;
-// ------------------------------------------------------------------
 void Standard_Type::Print (Standard_OStream& AStream) const
 {
   AStream << std::hex << (Standard_Address)this << " : " << std::dec << myName ;