Core/Conditions: Optimizations part 1 - use containers more suited for their role

This commit is contained in:
Shauren
2015-10-25 11:38:38 +01:00
parent 5e0cee85dd
commit 9fa938f3e0
4 changed files with 24 additions and 9 deletions

View File

@@ -179,4 +179,19 @@ namespace Trinity
}
}
//! Hash implementation for std::pair to allow using pairs in unordered_set or as key for unordered_map
//! Individual types used in pair must be hashable by boost::hash
namespace std
{
template<class K, class V>
struct hash<std::pair<K, V>>
{
public:
size_t operator()(std::pair<K, V> const& key) const
{
return boost::hash_value(key);
}
};
}
#endif

View File

@@ -2327,7 +2327,7 @@ void ConditionMgr::Clean()
NpcVendorConditionContainerStore.clear();
// this is a BIG hack, feel free to fix it if you can figure out the ConditionMgr ;)
for (std::list<Condition*>::const_iterator itr = AllocatedMemoryStore.begin(); itr != AllocatedMemoryStore.end(); ++itr)
for (std::vector<Condition*>::const_iterator itr = AllocatedMemoryStore.begin(); itr != AllocatedMemoryStore.end(); ++itr)
delete *itr;
AllocatedMemoryStore.clear();

View File

@@ -234,13 +234,13 @@ struct Condition
std::string ToString(bool ext = false) const; /// For logging purpose
};
typedef std::list<Condition*> ConditionContainer;
typedef std::map<uint32 /*SourceEntry*/, ConditionContainer> ConditionsByEntryMap;
typedef std::map<ConditionSourceType /*SourceType*/, ConditionsByEntryMap> ConditionEntriesByTypeMap;
typedef std::map<uint32, ConditionsByEntryMap> ConditionEntriesByCreatureIdMap;
typedef std::map<std::pair<int32, uint32 /*SAI source_type*/>, ConditionsByEntryMap> SmartEventConditionContainer;
typedef std::vector<Condition*> ConditionContainer;
typedef std::unordered_map<uint32 /*SourceEntry*/, ConditionContainer> ConditionsByEntryMap;
typedef std::unordered_map<ConditionSourceType /*SourceType*/, ConditionsByEntryMap> ConditionEntriesByTypeMap;
typedef std::unordered_map<uint32, ConditionsByEntryMap> ConditionEntriesByCreatureIdMap;
typedef std::unordered_map<std::pair<int32, uint32 /*SAI source_type*/>, ConditionsByEntryMap> SmartEventConditionContainer;
typedef std::map<uint32, ConditionContainer> ConditionReferenceContainer;//only used for references
typedef std::unordered_map<uint32, ConditionContainer> ConditionReferenceContainer;//only used for references
class ConditionMgr
{
@@ -294,7 +294,7 @@ class ConditionMgr
static void LogUselessConditionValue(Condition* cond, uint8 index, uint32 value);
void Clean(); // free up resources
std::list<Condition*> AllocatedMemoryStore; // some garbage collection :)
std::vector<Condition*> AllocatedMemoryStore; // some garbage collection :)
ConditionEntriesByTypeMap ConditionStore;
ConditionReferenceContainer ConditionReferenceStore;

View File

@@ -263,7 +263,7 @@ public:
uint32 TriggerSpell;
flag128 SpellClassMask;
float BonusCoefficientFromAP;
std::list<Condition*>* ImplicitTargetConditions;
std::vector<Condition*>* ImplicitTargetConditions;
// SpellScalingEntry
struct ScalingInfo
{