While you're doing cleanup, you may as well go a little further and remove some inefficiencies that might make sense in the context of a space-limited macro, but don't make sense in an addon. The current code is doing two things that aren't so great:
1. It's looking up the name of the target frame over and over. The target frame shows up to 32 buffs at a time, so you're potentially calling the same function 32 times. You can easily call it just once, store the name in a variable, and refer to that inside your loop:
Code:
hooksecurefunc("TargetFrame_UpdateAuras", function(s)
local name = s:GetName().."Buff"
for i=1,MAX_TARGET_BUFFS do
if select(5,UnitAura(s.unit,i)) == 'Magic' then
_G[name..i.."Stealable"]:Show()
end
end
end)
2. It's using the
select function. Unless you're
selecting value 940382423 out of a list, or are in some weird context where variables aren't an option, it's just a waste of CPU cycles. Just assign the return values and ignore the ones you don't need:
Code:
hooksecurefunc("TargetFrame_UpdateAuras", function(s)
local name = s:GetName().."Buff"
for i=1,MAX_TARGET_BUFFS do
local _,_,_,_,buffType=UnitAura(s.unit,i)
if buffType == 'Magic' then
_G[name..i.."Stealable"]:Show()
end
end
end)
Calling functions is the slowest thing you can do in an addon, so it's always good to avoid doing it more than you need to, especially in a situation like this one where your code is going to run very frequently.
Finally (not related to performance) you can add more whitespace to improve readability:
Code:
hooksecurefunc("TargetFrame_UpdateAuras", function(s)
local name = s:GetName() .. "Buff"
for i = 1 ,MAX_TARGET_BUFFS do
local _, _, _, _, buffType = UnitAura(s.unit, i)
if buffType == 'Magic' then
_G[name .. i .. "Stealable"]:Show()
end
end
end)