Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10988


Ignore:
Timestamp:
Dec 28, 2015, 11:22:21 PM (8 years ago)
Author:
landauf
Message:

use an unordered map and type_index to store identifiers by typeid

Location:
code/branches/cpp11_v2/src/libraries/core/class
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/libraries/core/class/IdentifierManager.cc

    r10916 r10988  
    6060
    6161        this->identifiers_.insert(identifier);
     62        this->identifierByTypeIndex_[identifier->getTypeInfo()] = identifier;
    6263        this->identifierByString_[identifier->getName()] = identifier;
    6364        this->identifierByLowercaseString_[getLowercase(identifier->getName())] = identifier;
     
    7172    {
    7273        this->identifiers_.erase(identifier);
     74        this->identifierByTypeIndex_.erase(identifier->getTypeInfo());
    7375        this->identifierByString_.erase(identifier->getName());
    7476        this->identifierByLowercaseString_.erase(getLowercase(identifier->getName()));
     
    258260    Identifier* IdentifierManager::getIdentifierByTypeInfo(const std::type_info& typeInfo)
    259261    {
    260         // TODO: use std::type_index and a map to find identifiers by type_info (only with c++11)
    261         for (Identifier* identifer : this->identifiers_)
    262             if (identifer->getTypeInfo() == typeInfo)
    263                 return identifer;
    264         return nullptr;
     262        auto it = this->identifierByTypeIndex_.find(typeInfo);
     263        if (it != this->identifierByTypeIndex_.end())
     264            return it->second;
     265        else
     266            return nullptr;
    265267    }
    266268
  • code/branches/cpp11_v2/src/libraries/core/class/IdentifierManager.h

    r10769 r10988  
    3737#include "core/CorePrereqs.h"
    3838
     39#include <typeindex>
    3940#include <map>
     41#include <unordered_map>
    4042#include <set>
    4143#include <list>
     
    102104                { hierarchyCreatingCounter_s--; }
    103105
    104             std::set<Identifier*> identifiers_;                              //!< All identifiers. This is only used internally.
    105             std::map<std::string, Identifier*> identifierByString_;          //!< Map that stores all Identifiers with their names.
    106             std::map<std::string, Identifier*> identifierByLowercaseString_; //!< Map that stores all Identifiers with their names in lowercase.
    107             std::map<uint32_t, Identifier*> identifierByNetworkId_;          //!< Returns the map that stores all Identifiers with their network IDs.
     106            std::set<Identifier*> identifiers_;                                      //!< All identifiers. This is only used internally.
     107            std::unordered_map<std::type_index, Identifier*> identifierByTypeIndex_; //!< Map that stores all Identifiers with their type_index.
     108            std::map<std::string, Identifier*> identifierByString_;                  //!< Map that stores all Identifiers with their names.
     109            std::map<std::string, Identifier*> identifierByLowercaseString_;         //!< Map that stores all Identifiers with their names in lowercase.
     110            std::map<uint32_t, Identifier*> identifierByNetworkId_;                  //!< Returns the map that stores all Identifiers with their network IDs.
    108111
    109112            int hierarchyCreatingCounter_s;                         //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading)
Note: See TracChangeset for help on using the changeset viewer.