]> OCCT Git - occt.git/commitdiff
0026551: Optimization of initialization of OCCT RTTI
authorabv <abv@opencascade.com>
Sat, 12 Dec 2015 16:07:35 +0000 (19:07 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 17 Dec 2015 13:41:29 +0000 (16:41 +0300)
Global instances of type descriptors are eliminated as unnecessary

src/Standard/Standard_Type.cxx
src/Standard/Standard_Type.hxx

index db12772aecc80956375851c7fe395ceb01e730ce..c07d1693a4f11edb13af7ff1c9906510823c1ffa 100644 (file)
@@ -37,8 +37,10 @@ Standard_Type::Standard_Type (const char* theSystemName,
                               const char* theName,
                               Standard_Size theSize,
                               const Handle(Standard_Type)& theParent) :
-  mySystemName (copy_string (theSystemName)),
-  myName(theName), mySize(theSize), myParent(theParent)
+  mySystemName(copy_string (theSystemName)),
+  myName(copy_string (theName)), 
+  mySize(theSize), 
+  myParent(theParent)
 {
 }
 
@@ -127,4 +129,5 @@ Standard_Type::~Standard_Type ()
 
 //  cout << "Unregistering " << mySystemName << ": " << aRegistry.Extent() << endl;
   Standard::Free (mySystemName);
+  Standard::Free (myName);
 }
index 5cb49b28e19e9102bb360bebe894308763d276c9..98317e3b5cacfef337d15ae48d3b296d1ced10ad 100644 (file)
@@ -57,7 +57,7 @@ public: \
 // forward declaration of type_instance class
 namespace opencascade {
   template <typename T>
-  class type_instance;
+  struct type_instance;
 }
 
 //! This class provides legacy interface (type descriptor) to run-time type
@@ -156,22 +156,18 @@ namespace opencascade {
 
   //! Template class providing instantiation of type descriptors as static
   //! variables (one per binary module). Having type descriptors defined as 
-  //! static variables is essential to ensure that everything gets initialized
-  //! during library loading and thus no concurrency occurs when type system
-  //! is accessed from multiple threads.
+  //! static variables is essential to ensure that descriptors are initialized
+  //! once and in correct order.
   template <typename T>
-  class type_instance
+  struct type_instance
   {
-    static Handle(Standard_Type) myInstance;
-  public:
     static const Handle(Standard_Type)& get ();
   };
 
   //! Specialization of type descriptor instance for void; returns null handle
   template <>
-  class type_instance<void>
+  struct type_instance<void>
   {
-  public:
     Standard_EXPORT static Handle(Standard_Type) get () { return 0; }
   };
 
@@ -180,8 +176,6 @@ namespace opencascade {
   template <typename T>
   const Handle(Standard_Type)& type_instance<T>::get ()
   {
-    (void)myInstance; // ensure that myInstance is instantiated
-
     // static variable inside function ensures that descriptors
     // are initialized in correct sequence
     static Handle(Standard_Type) anInstance =
@@ -190,11 +184,6 @@ namespace opencascade {
     return anInstance;
   }
 
-  // Static class field is defined to ensure initialization of all type
-  // descriptors at load time of the library
-  template <typename T>
-  Handle(Standard_Type) type_instance<T>::myInstance (get());
-
 }
 
 //! Operator printing type descriptor to stream