diff --git a/src/core/model/object.h b/src/core/model/object.h index 40505a661..3b8333d10 100644 --- a/src/core/model/object.h +++ b/src/core/model/object.h @@ -388,15 +388,18 @@ template Ptr Object::GetObject () const { + // This is an optimization: if the cast works (which is likely), + // things will be pretty fast. T *result = dynamic_cast (m_aggregates->buffer[0]); if (result != 0) { return Ptr (result); } + // if the cast does not work, we try to do a full type check. Ptr found = DoGetObject (T::GetTypeId ()); if (found != 0) { - return Ptr (dynamic_cast (PeekPointer (found))); + return Ptr (static_cast (PeekPointer (found))); } return 0; } @@ -408,7 +411,7 @@ Object::GetObject (TypeId tid) const Ptr found = DoGetObject (tid); if (found != 0) { - return Ptr (dynamic_cast (PeekPointer (found))); + return Ptr (static_cast (PeekPointer (found))); } return 0; }