Quantcast

Change internal implementation of spell lists.

Johnny C. Lam [06-10-13 - 21:34]
Change internal implementation of spell lists.

Move internal representation of spell lists from lists whose values are
the spell IDs to tables indexed by spell IDs with a default value of
"true".  This makes it easier to do the most common operation, which is to
check whether a given spell ID is in the spell list -- we can now do a
simple table lookup instead of walking the list.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@930 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleAura.lua
OvaleCompile.lua
OvaleCondition.lua
OvaleData.lua
OvaleState.lua
diff --git a/OvaleAura.lua b/OvaleAura.lua
index e26d2f6..189aca2 100644
--- a/OvaleAura.lua
+++ b/OvaleAura.lua
@@ -431,8 +431,8 @@ function OvaleAura:GetAura(unitId, spellId, filter, mine)
 		return self:GetAuraByGUID(guid, spellId, filter, mine, unitId)
 	elseif OvaleData.buffSpellList[spellId] then
 		local newStart, newEnding, newStacks, newTick, newValue, newGain
-		for _, v in pairs(OvaleData.buffSpellList[spellId]) do
-			local start, ending, stacks, tick, value, gain = self:GetAuraByGUID(guid, v, filter, mine, unitId)
+		for auraId in pairs(OvaleData.buffSpellList[spellId]) do
+			local start, ending, stacks, tick, value, gain = self:GetAuraByGUID(guid, auraId, filter, mine, unitId)
 			if start and (not newStart or stacks > newStacks) then
 				newStart = start
 				newEnding = ending
diff --git a/OvaleCompile.lua b/OvaleCompile.lua
index f307278..610b4d6 100644
--- a/OvaleCompile.lua
+++ b/OvaleCompile.lua
@@ -351,10 +351,11 @@ end

 local function ParseSpellList(name, params)
 	OvaleData.buffSpellList[name] = {}
-	local i = 1
 	for v in strgmatch(params, "(%d+)") do
-		OvaleData.buffSpellList[name][i] = tonumber(v)
-		i = i + 1
+		v = tonumber(v)
+		if v then
+			OvaleData.buffSpellList[name][v] = true
+		end
 	end
 end

@@ -368,24 +369,13 @@ local function ParseItemInfo(params)
 		for k, v in pairs(paramList) do
 			if k == "proc" then
 				-- Add the buff for this item proc to the spell list "item_proc_<proc>".
-				local buffId = paramList.buff
-				if buffId then
+				local buff = tonumber(paramList.buff)
+				if buff then
 					local listName = "item_proc_" .. v
 					if not OvaleData.buffSpellList[listName] then
 						OvaleData.buffSpellList[listName] = {}
 					end
-					local i = 1
-					local found = false
-					for _, buff in ipairs(OvaleData.buffSpellList[listName]) do
-						if buff == buffId then
-							found = true
-							break
-						end
-						i = i + 1
-					end
-					if not found then
-						OvaleData.buffSpellList[listName][i] = buffId
-					end
+					OvaleData.buffSpellList[listName][buff] = true
 				end
 			end
 		end
diff --git a/OvaleCondition.lua b/OvaleCondition.lua
index 803dde5..787fbad 100644
--- a/OvaleCondition.lua
+++ b/OvaleCondition.lua
@@ -785,8 +785,8 @@ OvaleCondition.conditions.casting = function(condition)
 		end
 	elseif OvaleData.buffSpellList[spellId] then
 		local found = false
-		for k,v in pairs(OvaleData.buffSpellList[spellId]) do
-			if IsSameSpell(v, castSpellId, castSpellName) then
+		for auraId in pairs(OvaleData.buffSpellList[spellId]) do
+			if IsSameSpell(auraId, castSpellId, castSpellName) then
 				return start, ending
 			end
 		end
@@ -1626,8 +1626,7 @@ end
 -- if IsFeared() Spell(every_man_for_himself)

 OvaleCondition.conditions.isfeared = function(condition)
-	local fearSpellList = OvaleData:GetFearSpellList()
-	return TestBoolean(not API_HasFullControl() and isDebuffInList(fearSpellList), condition[1])
+	return TestBoolean(not API_HasFullControl() and isDebuffInList(OvaleData.buffSpellList.fear), condition[1])
 end

 --- Test if the target is friendly to the player.
@@ -1675,8 +1674,7 @@ end
 -- if IsIncapacitated() Spell(every_man_for_himself)

 OvaleCondition.conditions.isincapacitated = function(condition)
-	local incapacitateSpellList = OvaleData:GetIncapacitateSpellList()
-	return TestBoolean(not API_HasFullControl() and isDebuffInList(incapacitateSpellList), condition[1])
+	return TestBoolean(not API_HasFullControl() and isDebuffInList(OvaleData.buffSpellList.incapacitate), condition[1])
 end

 --- Test if the target is currently casting an interruptible spell.
@@ -1712,8 +1710,7 @@ end
 -- if IsRooted() Item(Trinket0Slot usable=1)

 OvaleCondition.conditions.isrooted = function(condition)
-	local rootSpellList = OvaleData:GetRootSpellList()
-	return TestBoolean(isDebuffInList(rootSpellList), condition[1])
+	return TestBoolean(isDebuffInList(OvaleData.buffSpellList.root), condition[1])
 end

 --- Test if the player is stunned.
@@ -1727,8 +1724,7 @@ end
 -- if IsStunned() Item(Trinket0Slot usable=1)

 OvaleCondition.conditions.isstunned = function(condition)
-	local stunSpellList = OvaleData:GetStunSpellList()
-	return TestBoolean(not API_HasFullControl() and isDebuffInList(stunSpellList), condition[1])
+	return TestBoolean(not API_HasFullControl() and isDebuffInList(OvaleData.buffSpellList.stun), condition[1])
 end

 --- Get the damage done by the most recent damage event for the given spell.
diff --git a/OvaleData.lua b/OvaleData.lua
index 1aa9d97..f01002d 100644
--- a/OvaleData.lua
+++ b/OvaleData.lua
@@ -106,189 +106,188 @@ OvaleData.buffSpellList =
 	-- Debuffs
 	fear =
 	{
-		5782, -- Fear
-		5484, -- Howl of terror
-		5246, -- Intimidating Shout
-		8122, -- Psychic scream
+		[5782] = true, -- Fear
+		[5484] = true, -- Howl of terror
+		[5246] = true, -- Intimidating Shout
+		[8122] = true, -- Psychic scream
 	},
 	incapacitate =
 	{
-		6770, -- Sap
-		12540, -- Gouge
-		20066, -- Repentance
+		[6770] = true, -- Sap
+		[12540] = true, -- Gouge
+		[20066] = true, -- Repentance
 	},
 	root =
 	{
-		23694, -- Improved Hamstring
-		339, -- Entangling Roots
-		122, -- Frost Nova
-		47168, -- Improved Wing Clip
+		[23694] = true, -- Improved Hamstring
+		[339] = true, -- Entangling Roots
+		[122] = true, -- Frost Nova
+		[47168] = true, -- Improved Wing Clip
 	},
 	stun =
 	{
-		5211, -- Bash
-		44415, -- Blackout
-		6409, -- Cheap Shot
-		22427, -- Concussion Blow
-		853, -- Hammer of Justice
-		408, -- Kidney Shot
-		46968, -- Shockwave
+		[5211] = true, -- Bash
+		[44415] = true, -- Blackout
+		[6409] = true, -- Cheap Shot
+		[22427] = true, -- Concussion Blow
+		[853] = true, -- Hammer of Justice
+		[408] = true, -- Kidney Shot
+		[46968] = true, -- Shockwave
 	},

 	-- Raid buffs
 	attack_power_multiplier=
 	{
-		6673, -- Battle Shout (warrior)
-		19506, -- Trueshot Aura (hunter)
-		57330, -- Horn of Winter (death knight)
+		[6673] = true, -- Battle Shout (warrior)
+		[19506] = true, -- Trueshot Aura (hunter)
+		[57330] = true, -- Horn of Winter (death knight)
 	},
 	critical_strike =
 	{
-		--Guardian and Feral druids, any hunter, any mage
-		1459, -- Arcane Brillance (mage)
-		24604, -- Furious Howl (wolf)
-		24932, -- Leader of the Pack (feral & guardian druids)
-		61316, -- Dalaran Brilliance (mage)
-		90309, -- Terrifying Roar (devilsaur)
-		97229, -- Bellowing Roar (hydra)
-		116781, -- Legacy of the White Tiger (windwalker monk)
-		126309, -- Still Water (waterstrider)
-		126373, -- Fearless Roar (quilen)
+		[1459] = true, -- Arcane Brillance (mage)
+		[24604] = true, -- Furious Howl (wolf)
+		[24932] = true, -- Leader of the Pack (feral & guardian druids)
+		[61316] = true, -- Dalaran Brilliance (mage)
+		[90309] = true, -- Terrifying Roar (devilsaur)
+		[97229] = true, -- Bellowing Roar (hydra)
+		[116781] = true, -- Legacy of the White Tiger (windwalker monk)
+		[126309] = true, -- Still Water (waterstrider)
+		[126373] = true, -- Fearless Roar (quilen)
 	},
 	mastery =
 	{
-		19740, -- Blessing of Might (paladin)
-		93435, -- Roar of Courage (cat)
-		116956, -- Grace of Air (shaman)
-		128997, -- Spirit Beast Blessing (spirit beast)
+		[19740] = true, -- Blessing of Might (paladin)
+		[93435] = true, -- Roar of Courage (cat)
+		[116956] = true, -- Grace of Air (shaman)
+		[128997] = true, -- Spirit Beast Blessing (spirit beast)
 	},
 	melee_haste =
 	{
-		30809, -- Unleashed Rage (enhancement shaman)
-		55610, -- Unholy Aura (frost & unholy death knights)
-		113742, -- Swiftblade's Cunning (rogue)
-		128432, -- Cackling Howl (hyena)
-		128433, -- Serpent's Swiftness (serpent)
+		[30809] = true, -- Unleashed Rage (enhancement shaman)
+		[55610] = true, -- Unholy Aura (frost & unholy death knights)
+		[113742] = true, -- Swiftblade's Cunning (rogue)
+		[128432] = true, -- Cackling Howl (hyena)
+		[128433] = true, -- Serpent's Swiftness (serpent)
 	},
 	spell_power_multiplier =
 	{
-		1459, -- Arcane Brillancen (mage)
-		61316, -- Dalaran Brilliance (mage)
-		77747, -- Burning Wrath (shaman)
-		109773,  -- Dark Intent (warlock)
-		126309, -- Still Water (waterstrider)
+		[1459] = true, -- Arcane Brillancen (mage)
+		[61316] = true, -- Dalaran Brilliance (mage)
+		[77747] = true, -- Burning Wrath (shaman)
+		[109773] = true,  -- Dark Intent (warlock)
+		[126309] = true, -- Still Water (waterstrider)
 	},
 	stamina =
 	{
-		469, -- Commanding Shout (warrior)
-		21562, -- Power Word: Fortitude (priest)
-		90364, -- Qiraji Fortitude (silithid)
-		109773,  -- Dark Intent (warlock)
+		[469] = true, -- Commanding Shout (warrior)
+		[21562] = true, -- Power Word: Fortitude (priest)
+		[90364] = true, -- Qiraji Fortitude (silithid)
+		[109773] = true,  -- Dark Intent (warlock)
 	},
 	str_agi_int =
 	{
-		1126, -- Mark of the Wild (druid)
-		20217, -- Blessing of Kings (paladin)
-		90363, -- Embrace of the Shale Spider (shale spider)
-		117666, -- Legacy of the Emporer (monk)
+		[1126] = true, -- Mark of the Wild (druid)
+		[20217] = true, -- Blessing of Kings (paladin)
+		[90363] = true, -- Embrace of the Shale Spider (shale spider)
+		[117666] = true, -- Legacy of the Emporer (monk)
 	},
 	spell_haste =
 	{
-		24907, -- Moonkin aura (balance druid)
-		49868, -- Mind Quickening (shadow priest)
-		51470, -- Elemental Oath (elemental shaman)
-		135678, -- Energizing Spores (sporebat)
+		[24907] = true, -- Moonkin aura (balance druid)
+		[49868] = true, -- Mind Quickening (shadow priest)
+		[51470] = true, -- Elemental Oath (elemental shaman)
+		[135678] = true, -- Energizing Spores (sporebat)
 	},

 	-- Target debuffs
 	bleed =
 	{
-		1079, -- Rip (feral druid)
-		1822, -- Rake (cat druid)
-		9007, -- Pounce Bleed (cat druid)
-		33745, -- Lacerate (bear druid)
-		63468, -- Piercing Shots (marksmanship hunter)
-		77758, -- Thrash (bear druid)
-		103830, -- Thrash (cat druid)
-		113344, -- Bloodbath (warrior)
-		115767, -- Deep Wounds (warrior)
-		120699, -- Lynx Rush (hunter)
-		122233, -- Crimson Tempest (rogue)
+		[1079] = true, -- Rip (feral druid)
+		[1822] = true, -- Rake (cat druid)
+		[9007] = true, -- Pounce Bleed (cat druid)
+		[33745] = true, -- Lacerate (bear druid)
+		[63468] = true, -- Piercing Shots (marksmanship hunter)
+		[77758] = true, -- Thrash (bear druid)
+		[103830] = true, -- Thrash (cat druid)
+		[113344] = true, -- Bloodbath (warrior)
+		[115767] = true, -- Deep Wounds (warrior)
+		[120699] = true, -- Lynx Rush (hunter)
+		[122233] = true, -- Crimson Tempest (rogue)
 	},
 	cast_slow =
 	{
-		5760, -- Mind-numbing Poison (rogue)
-		31589, -- Slow (arcane mage)
-		50274, -- Spore Cloud (sporebat)
-		58604, -- Lava Breath (core hound)
-		73975, -- Necrotic Strike (death knight)
-		90315, -- Tailspin (fox)
-		109466, -- Curse of Enfeeblement (warlock)
-		126406, -- Trample (goat)
+		[5760] = true, -- Mind-numbing Poison (rogue)
+		[31589] = true, -- Slow (arcane mage)
+		[50274] = true, -- Spore Cloud (sporebat)
+		[58604] = true, -- Lava Breath (core hound)
+		[73975] = true, -- Necrotic Strike (death knight)
+		[90315] = true, -- Tailspin (fox)
+		[109466] = true, -- Curse of Enfeeblement (warlock)
+		[126406] = true, -- Trample (goat)
 	},
 	healing_reduced =
 	{
-		8680, -- Wound Poison (rogue)
-		54680, -- Monstrous Bite (devilsaur)
-		82654, -- Widow Venom (hunter)
-		115804, -- Mortal Wounds (arms & fury warriors, windwalker monk, warlock)
+		[8680] = true, -- Wound Poison (rogue)
+		[54680] = true, -- Monstrous Bite (devilsaur)
+		[82654] = true, -- Widow Venom (hunter)
+		[115804] = true, -- Mortal Wounds (arms & fury warriors, windwalker monk, warlock)
 	},
 	lower_physical_damage=
 	{
-		24423, -- Demoralizing Screech (carrion bird)
-		50256, -- Demoralizing Roar (bear)
-		115798, -- Weakened Blows (all tank specs, feral druid, retribution paladin, shaman, warlock, warrior)
+		[24423] = true, -- Demoralizing Screech (carrion bird)
+		[50256] = true, -- Demoralizing Roar (bear)
+		[115798] = true, -- Weakened Blows (all tank specs, feral druid, retribution paladin, shaman, warlock, warrior)
 	},
 	magic_vulnerability=
 	{
-		1490, -- Curse of the Elements (warlock)
-		24844, -- Lightning Breath (wind serpent)
-		34889, -- Fire Breath (dragonhawk)
-		93068, -- Master Poisoner (rogue)
-		104225, -- Soulburn: Curse of the Elements (warlock)
+		[1490] = true, -- Curse of the Elements (warlock)
+		[24844] = true, -- Lightning Breath (wind serpent)
+		[34889] = true, -- Fire Breath (dragonhawk)
+		[93068] = true, -- Master Poisoner (rogue)
+		[104225] = true, -- Soulburn: Curse of the Elements (warlock)
 	},
 	physical_vulnerability=
 	{
-		35290, -- Gore (boar)
-		50518, -- Ravage (ravager)
-		55749, -- Acid Spit (worm)
-		57386, -- Stampede (rhino)
-		81326, -- Physical Vulnerability (frost & unholy death knights, retribution paladin, arms & fury warriors)
+		[35290] = true, -- Gore (boar)
+		[50518] = true, -- Ravage (ravager)
+		[55749] = true, -- Acid Spit (worm)
+		[57386] = true, -- Stampede (rhino)
+		[81326] = true, -- Physical Vulnerability (frost & unholy death knights, retribution paladin, arms & fury warriors)
 	},
 	ranged_vulnerability =
 	{
-		1130, -- Hunter's Mark
+		[1130] = true, -- Hunter's Mark
 	},

 	-- Target buffs
 	enrage =
 	{
-		12292, -- Bloodbath (warrior)
-		12880, -- Enrage (warrior)
-		18499, -- Berserker Rage (warrior)
-		49016, -- Unholy Frenzy (death knight)
-		76691, -- Vengeance (all tank specs)
-		132365, -- Vengeance (all tank specs)
+		[12292] = true, -- Bloodbath (warrior)
+		[12880] = true, -- Enrage (warrior)
+		[18499] = true, -- Berserker Rage (warrior)
+		[49016] = true, -- Unholy Frenzy (death knight)
+		[76691] = true, -- Vengeance (all tank specs)
+		[132365] = true, -- Vengeance (all tank specs)
 	},

 	-- Raid buffs (short term)
 	burst_haste =
 	{
-		2825, --Bloodlust (Horde shaman)
-		32182, --Heroism (Alliance shaman)
-		80353, --Time Warp (mage)
-		90355, -- Ancient Hysteria (core hound)
+		[2825] = true, --Bloodlust (Horde shaman)
+		[32182] = true, --Heroism (Alliance shaman)
+		[80353] = true, --Time Warp (mage)
+		[90355] = true, -- Ancient Hysteria (core hound)
 	},
 	burst_haste_debuff =
 	{
-		57723, -- Exhaustion (Heroism)
-		57724, -- Sated (Bloodlust)
-		80354, -- Temporal Displacement (Time Warp)
-		95809, -- Insanity (Ancient Hysteria)
+		[57723] = true, -- Exhaustion (Heroism)
+		[57724] = true, -- Sated (Bloodlust)
+		[80354] = true, -- Temporal Displacement (Time Warp)
+		[95809] = true, -- Insanity (Ancient Hysteria)
 	},
 	raid_movement =
 	{
-		106898, -- Stampeding Roar
+		[106898] = true, -- Stampeding Roar
 	}
 }
 OvaleData.buffSpellList.bloodlust_aura = OvaleData.buffSpellList.burst_haste
@@ -297,13 +296,6 @@ OvaleData.buffSpellList.heroism_aura = OvaleData.buffSpellList.burst_haste
 OvaleData.buffSpellList.heroism = OvaleData.buffSpellList.burst_haste
 --</public-static-properties>

---<private-static-properties>
-local fearSpellList = nil
-local stunSpellList = nil
-local incapacitateSpellList = nil
-local rootSpellList = nil
---</private-static-properties>
-
 --<public-static-methods>
 function OvaleData:OnInitialize()
 	for k,v in pairs(self.power) do
@@ -345,50 +337,6 @@ function OvaleData:Update()
 	self:FillSpellList()
 end

-function OvaleData:GetRootSpellList()
-	if rootSpellList then
-		return rootSpellList
-	end
-	rootSpellList = {}
-	for k, v in pairs(self.buffSpellList.fear) do
-		rootSpellList[v] = true
-	end
-	return rootSpellList
-end
-
-function OvaleData:GetStunSpellList()
-	if stunSpellList then
-		return stunSpellList
-	end
-	stunSpellList = {}
-	for k, v in pairs(self.buffSpellList.stun) do
-		stunSpellList[v] = true
-	end
-	return stunSpellList
-end
-
-function OvaleData:GetIncapacitateSpellList()
-	if incapacitateSpellList then
-		return incapacitateSpellList
-	end
-	incapacitateSpellList = {}
-	for k, v in pairs(self.buffSpellList.incapacitate) do
-		incapacitateSpellList[v] = true
-	end
-	return incapacitateSpellList
-end
-
-function OvaleData:GetFearSpellList()
-	if fearSpellList then
-		return fearSpellList
-	end
-	fearSpellList = {}
-	for k, v in pairs(self.buffSpellList.fear) do
-		fearSpellList[v] = true
-	end
-	return fearSpellList
-end
-
 function OvaleData:GetSpellName(spellId)
 	if not spellId then return nil end
 	return self.spellList[spellId] or API_GetSpellInfo(spellId)
@@ -580,10 +528,10 @@ function OvaleData:GetDuration(spellId, combo, holy)
 	if type(spellId) == "number" then
 		si = self.spellInfo[spellId]
 	elseif OvaleData.buffSpellList[spellId] then
-		for _, v in pairs(OvaleData.buffSpellList[spellId]) do
-			si = self.spellInfo[v]
+		for auraId in pairs(OvaleData.buffSpellList[spellId]) do
+			si = self.spellInfo[auraId]
 			if si then
-				spellId = v
+				spellId = auraId
 				break
 			end
 		end
@@ -616,8 +564,8 @@ function OvaleData:GetTickLength(spellId)
 	if type(spellId) == "number" then
 		si = self.spellInfo[spellId]
 	elseif OvaleData.buffSpellList[spellId] then
-		for _, spellId in pairs(OvaleData.buffSpellList[spellId]) do
-			si = self.spellInfo[spellId]
+		for auraId in pairs(OvaleData.buffSpellList[spellId]) do
+			si = self.spellInfo[auraId]
 			if si then break end
 		end
 	end
diff --git a/OvaleState.lua b/OvaleState.lua
index 39a9820..dbdf8ff 100644
--- a/OvaleState.lua
+++ b/OvaleState.lua
@@ -88,11 +88,8 @@ function OvaleState:UpdatePowerRates()
 	-- Strip off 10% attack speed bonus that doesn't count toward power regeneration.
 	if class == "HUNTER" then
 		-- Strip off 10% attack speed bonus that doesn't count toward focus regeneration.
-		for _, v in pairs(OvaleData.buffSpellList.melee_haste) do
-			if OvaleState:GetAura("player", v) then
-				focusRegen = focusRegen / 1.1
-				break
-			end
+		if OvaleState:GetAura("player", "melee_haste") then
+			focusRegen = focusRegen / 1.1
 		end
 	elseif class == "MONK" then
 		-- Way of the Monk (monk)
@@ -571,8 +568,8 @@ function OvaleState:GetAura(unitId, spellId, filter, mine)
 		return self:GetAuraByGUID(guid, spellId, filter, mine, unitId)
 	elseif OvaleData.buffSpellList[spellId] then
 		local newStart, newEnding, newStacks, newTick, newValue, newGain
-		for _, v in pairs(OvaleData.buffSpellList[spellId]) do
-			local start, ending, stacks, tick, value, gain = self:GetAuraByGUID(guid, v, filter, mine, unitId)
+		for auraId in pairs(OvaleData.buffSpellList[spellId]) do
+			local start, ending, stacks, tick, value, gain = self:GetAuraByGUID(guid, auraId, filter, mine, unitId)
 			if start and (not newStart or stacks > newStacks) then
 				newStart = start
 				newEnding = ending