bug 1094: Object::GetObject upon dlopen
authorMathieu Lacage <mathieu.lacage@inria.fr>
Tue, 05 Apr 2011 21:39:39 +0200
changeset 6997 00c8ea8e9e40
parent 6996 53f1bfb3e91c
child 6998 1c2b8cfb71d2
bug 1094: Object::GetObject upon dlopen
src/core/model/object.h
--- a/src/core/model/object.h	Mon Apr 04 19:44:35 2011 +0100
+++ b/src/core/model/object.h	Tue Apr 05 21:39:39 2011 +0200
@@ -388,15 +388,18 @@
 Ptr<T> 
 Object::GetObject () const
 {
+  // This is an optimization: if the cast works (which is likely),
+  // things will be pretty fast.
   T *result = dynamic_cast<T *> (m_aggregates->buffer[0]);
   if (result != 0)
     {
       return Ptr<T> (result);
     }
+  // if the cast does not work, we try to do a full type check.
   Ptr<Object> found = DoGetObject (T::GetTypeId ());
   if (found != 0)
     {
-      return Ptr<T> (dynamic_cast<T *> (PeekPointer (found)));
+      return Ptr<T> (static_cast<T *> (PeekPointer (found)));
     }
   return 0;
 }
@@ -408,7 +411,7 @@
   Ptr<Object> found = DoGetObject (tid);
   if (found != 0)
     {
-      return Ptr<T> (dynamic_cast<T *> (PeekPointer (found)));
+      return Ptr<T> (static_cast<T *> (PeekPointer (found)));
     }
   return 0;
 }