Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 15, 2009, 1:26:23 AM (15 years ago)
Author:
rgrieder
Message:
  • Using std::vector instead of std::list in register/unregister Iterator/ObjectListIterator. That is approximately 6 times faster because the list has very few elements.
  • Inlined getIdentifier() for sure by exporting the heavy part to another function.
  • Also eliminated the need of isFirstCall() because the "static initialisation chaos" only applies to variables that cannot be evaluated at compile time.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/core/Identifier.h

    r2710 r2784  
    357357            static ClassIdentifier<T> *getIdentifier(const std::string& name);
    358358            void addObject(T* object);
    359             static bool isFirstCall();
    360359
    361360            void updateConfigValues(bool updateChildren = true) const;
    362361
    363362        private:
     363            static void initialiseIdentifier();
    364364            ClassIdentifier(const ClassIdentifier<T>& identifier) {}    // don't copy
    365365            ClassIdentifier()
     
    376376
    377377    template <class T>
    378     ClassIdentifier<T>* ClassIdentifier<T>::classIdentifier_s;
    379 
    380     /**
    381         @brief Returns true if the function gets called the first time, false otherwise.
    382         @return True if this function got called the first time.
    383     */
    384     template <class T>
    385     bool ClassIdentifier<T>::isFirstCall()
    386     {
    387         static bool bFirstCall = true;
    388 
    389         if (bFirstCall)
     378    ClassIdentifier<T>* ClassIdentifier<T>::classIdentifier_s = 0;
     379
     380    /**
     381        @brief Returns the only instance of this class.
     382        @return The unique Identifier
     383    */
     384    template <class T>
     385    ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()
     386    {
     387        // check if the static field has already been filled
     388        if (ClassIdentifier<T>::classIdentifier_s == 0)
     389            ClassIdentifier<T>::initialiseIdentifier();
     390
     391        return ClassIdentifier<T>::classIdentifier_s;
     392    }
     393
     394    /**
     395        @brief Does the same as getIdentifier() but sets the name if this wasn't done yet.
     396        @param name The name of this Identifier
     397        @return The Identifier
     398    */
     399    template <class T>
     400    ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier(const std::string& name)
     401    {
     402        ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier();
     403        identifier->setName(name);
     404        return identifier;
     405    }
     406
     407    /**
     408        @brief Assigns the static field for the identifier singleton.
     409    */
     410    template <class T>
     411    void ClassIdentifier<T>::initialiseIdentifier()
     412    {
     413        // Get the name of the class
     414        std::string name = typeid(T).name();
     415
     416        // create a new identifier anyway. Will be deleted in Identifier::getIdentifier if not used.
     417        ClassIdentifier<T>* proposal = new ClassIdentifier<T>();
     418
     419        // Get the entry from the map
     420        ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)Identifier::getIdentifierSingleton(name, proposal);
     421
     422        if (ClassIdentifier<T>::classIdentifier_s == proposal)
    390423        {
    391             bFirstCall = false;
    392             return true;
     424            COUT(4) << "*** Identifier: Requested Identifier for " << name << " was not yet existing and got created." << std::endl;
    393425        }
    394426        else
    395427        {
    396             return false;
     428            COUT(4) << "*** Identifier: Requested Identifier for " << name << " was already existing and got assigned." << std::endl;
    397429        }
    398     }
    399 
    400     /**
    401         @brief Returns the only instance of this class.
    402         @return The unique Identifier
    403     */
    404     template <class T>
    405     ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()
    406     {
    407         // check if the static field has already been filled
    408         if (ClassIdentifier<T>::isFirstCall())
    409         {
    410             // Get the name of the class
    411             std::string name = typeid(T).name();
    412 
    413             // create a new identifier anyway. Will be deleted in Identifier::getIdentifier if not used.
    414             ClassIdentifier<T>* proposal = new ClassIdentifier<T>();
    415 
    416             // Get the entry from the map
    417             ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)Identifier::getIdentifierSingleton(name, proposal);
    418 
    419             if (ClassIdentifier<T>::classIdentifier_s == proposal)
    420             {
    421                 COUT(4) << "*** Identifier: Requested Identifier for " << name << " was not yet existing and got created." << std::endl;
    422             }
    423             else
    424             {
    425                 COUT(4) << "*** Identifier: Requested Identifier for " << name << " was already existing and got assigned." << std::endl;
    426             }
    427         }
    428 
    429         // Finally return the unique ClassIdentifier
    430         return ClassIdentifier<T>::classIdentifier_s;
    431     }
    432 
    433     /**
    434         @brief Does the same as getIdentifier() but sets the name if this wasn't done yet.
    435         @param name The name of this Identifier
    436         @return The Identifier
    437     */
    438     template <class T>
    439     ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier(const std::string& name)
    440     {
    441         ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier();
    442         identifier->setName(name);
    443         return identifier;
    444430    }
    445431
Note: See TracChangeset for help on using the changeset viewer.