aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2015-10-25 11:38:38 +0100
committerShauren <shauren.trinity@gmail.com>2015-10-31 20:26:40 +0100
commit31586056034fe730a7a89ddc7200e9087a9440aa (patch)
treee42936ae1ed2eb3697c17627506a272230505eb9 /src
parentdc74454356af726c96c83b02418d46bc664cee8e (diff)
Core/Conditions: Optimizations part 1 - use containers more suited for their role
(cherry picked from commit 9fa938f3e0df2ca6b9ff4f800a5b41ba18cdd214)
Diffstat (limited to 'src')
-rw-r--r--src/common/Common.h15
-rw-r--r--src/server/game/Conditions/ConditionMgr.cpp2
-rw-r--r--src/server/game/Conditions/ConditionMgr.h14
-rw-r--r--src/server/game/Spells/SpellInfo.h2
4 files changed, 24 insertions, 9 deletions
diff --git a/src/common/Common.h b/src/common/Common.h
index 908cd487822..7a1ea247a94 100644
--- a/src/common/Common.h
+++ b/src/common/Common.h
@@ -161,4 +161,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
diff --git a/src/server/game/Conditions/ConditionMgr.cpp b/src/server/game/Conditions/ConditionMgr.cpp
index 2a7cdc3d50b..32314d92fdc 100644
--- a/src/server/game/Conditions/ConditionMgr.cpp
+++ b/src/server/game/Conditions/ConditionMgr.cpp
@@ -2187,7 +2187,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();
diff --git a/src/server/game/Conditions/ConditionMgr.h b/src/server/game/Conditions/ConditionMgr.h
index ff429cdbd26..0411e421c56 100644
--- a/src/server/game/Conditions/ConditionMgr.h
+++ b/src/server/game/Conditions/ConditionMgr.h
@@ -213,13 +213,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
{
@@ -271,7 +271,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;
diff --git a/src/server/game/Spells/SpellInfo.h b/src/server/game/Spells/SpellInfo.h
index ecb55b25afd..241e7df9544 100644
--- a/src/server/game/Spells/SpellInfo.h
+++ b/src/server/game/Spells/SpellInfo.h
@@ -249,7 +249,7 @@ public:
uint32 ItemType;
uint32 TriggerSpell;
flag96 SpellClassMask;
- std::list<Condition*>* ImplicitTargetConditions;
+ std::vector<Condition*>* ImplicitTargetConditions;
SpellEffectInfo() : _spellInfo(NULL), _effIndex(0), Effect(0), ApplyAuraName(0), Amplitude(0), DieSides(0),
RealPointsPerLevel(0), BasePoints(0), PointsPerComboPoint(0), ValueMultiplier(0), DamageMultiplier(0),