Fix: optimize execution performance and memory usage via caching and table reuse

This commit is contained in:
Bluewhale1337
2026-09-16 10:24:33 +02:00
parent 7f4d4be827
commit 55bc6f1ea0
5 changed files with 45 additions and 19 deletions
+6 -1
View File
@@ -41,6 +41,7 @@ function HealBot_CheckShamanWeaponBuff(spellName)
if not firstWord then return false end
HealBot_ScanTooltip:SetOwner(UIParent, "ANCHOR_NONE")
if not HealBot_ScanTooltip_Lines then HealBot_ScanTooltip_Lines = {} end
local slots = HealBot_GetTable()
if hasMainHandEnchant then table.insert(slots, 16) end
if hasOffHandEnchant then table.insert(slots, 17) end
@@ -49,7 +50,11 @@ function HealBot_CheckShamanWeaponBuff(spellName)
HealBot_ScanTooltip:ClearLines()
HealBot_ScanTooltip:SetInventoryItem("player", slot)
for i = 1, HealBot_ScanTooltip:NumLines() do
local textObj = getglobal("HealBot_ScanTooltipTextLeft" .. i)
local textObj = HealBot_ScanTooltip_Lines[i]
if not textObj then
textObj = getglobal("HealBot_ScanTooltipTextLeft" .. i)
HealBot_ScanTooltip_Lines[i] = textObj
end
if textObj then
local text = textObj:GetText()
if text and string.find(text, firstWord) then
+6 -6
View File
@@ -69,11 +69,11 @@ function HealBot_OnUpdate(this, arg1)
local pending = HealBot_TargetRestorePending;
HealBot_TargetRestorePending = nil;
HealBot_TargetRestoreTimer = 0;
if pending.type == "enemy" then
if pending == "enemy" then
TargetLastEnemy();
elseif pending.type == "friend" then
elseif pending == "friend" then
TargetLastTarget();
elseif pending.type == "clear" then
elseif pending == "clear" then
ClearTarget();
end
end
@@ -112,11 +112,11 @@ function HealBot_OnUpdate(this, arg1)
-- Restore target logic
if pendingCast.targetEnemy then
HealBot_TargetRestorePending = { type = "enemy" }
HealBot_TargetRestorePending = "enemy"
elseif pendingCast.oldTarget and pendingCast.oldTarget ~= UnitName(pendingCast.target) then
HealBot_TargetRestorePending = { type = "friend" }
HealBot_TargetRestorePending = "friend"
elseif not pendingCast.oldTarget then
HealBot_TargetRestorePending = { type = "clear" }
HealBot_TargetRestorePending = "clear"
end
HealBot_TargetRestoreTimer = 0
end
+27 -8
View File
@@ -237,7 +237,7 @@ function HealBot_StopCasting()
local ag = HealBot_Config.babortcolg[HealBot_Config.Current_Skin] or 0.1;
local ab = HealBot_Config.babortcolb[HealBot_Config.Current_Skin] or 0.5;
local aa = HealBot_Config.babortcola[HealBot_Config.Current_Skin] or 1;
bar.txt = getglobal(bar:GetName() .. "_text");
if not bar.txt then bar.txt = getglobal(bar:GetName() .. "_text") end
bar:SetStatusBarColor(ar, ag, ab, 0);
local sr = HealBot_Config.btextdisbledcolr[HealBot_Config.Current_Skin];
local sg = HealBot_Config.btextdisbledcolg[HealBot_Config.Current_Skin];
@@ -303,7 +303,7 @@ function HealBot_CheckCasting(unit)
local sg = HealBot_Config.btextenabledcolg[HealBot_Config.Current_Skin];
local sb = HealBot_Config.btextenabledcolb[HealBot_Config.Current_Skin];
local sa = HealBot_Config.btextenabledcola[HealBot_Config.Current_Skin];
bar.txt = getglobal(bar:GetName() .. "_text");
if not bar.txt then bar.txt = getglobal(bar:GetName() .. "_text") end
bar.txt:SetTextColor(sr, sg, sb, sa);
end
end
@@ -328,7 +328,15 @@ function HealBot_CastSpellOnFriend(spell, target)
if formCancelled then
-- ALWAYS put the cast into the Pending queue so the OnUpdate loop can wait for the server
-- to process the unshift before attempting the cast, otherwise we get "You are in shapeshift form".
HealBot_PendingShapeshiftCast = { spell = spell, target = target, targetEnemy = targetEnemy, oldTarget = oldTarget, fireTime = GetTime() + 0.05, expires = GetTime() + 2.0 }
if not HealBot_PendingShapeshiftCast then HealBot_PendingShapeshiftCast = {} end
HealBot_PendingShapeshiftCast.spell = spell
HealBot_PendingShapeshiftCast.target = target
HealBot_PendingShapeshiftCast.targetEnemy = targetEnemy
HealBot_PendingShapeshiftCast.oldTarget = oldTarget
HealBot_PendingShapeshiftCast.fireTime = GetTime() + 0.05
HealBot_PendingShapeshiftCast.expires = GetTime() + 2.0
HealBot_PendingShapeshiftCast.started = nil
HealBot_PendingShapeshiftCast.nextSpam = nil
return;
end
@@ -339,11 +347,11 @@ function HealBot_CastSpellOnFriend(spell, target)
HealBot_StartCasting(spell, target, "direct");
if targetEnemy then
HealBot_TargetRestorePending = { type = "enemy" };
HealBot_TargetRestorePending = "enemy";
elseif oldTarget and oldTarget ~= UnitName(target) then
HealBot_TargetRestorePending = { type = "friend" };
HealBot_TargetRestorePending = "friend";
elseif not oldTarget then
HealBot_TargetRestorePending = { type = "clear" };
HealBot_TargetRestorePending = "clear";
end
HealBot_TargetRestoreTimer = 0;
end
@@ -674,8 +682,15 @@ function HealBot_InitGetSpellData(spell, id, class)
_cast = 0;
line = nil;
if not HealBot_ScanTooltip_Lines_Left then HealBot_ScanTooltip_Lines_Left = {} end
if not HealBot_ScanTooltip_Lines_Right then HealBot_ScanTooltip_Lines_Right = {} end
for lineNum = 2, 6 do
local lText = getglobal("HealBot_ScanTooltipTextLeft"..lineNum);
local lText = HealBot_ScanTooltip_Lines_Left[lineNum];
if not lText then
lText = getglobal("HealBot_ScanTooltipTextLeft"..lineNum);
HealBot_ScanTooltip_Lines_Left[lineNum] = lText;
end
if lText and lText:IsVisible() and lText:GetText() then
local txt = lText:GetText();
local t1, t2, match;
@@ -699,7 +714,11 @@ function HealBot_InitGetSpellData(spell, id, class)
end
end
local rText = getglobal("HealBot_ScanTooltipTextRight"..lineNum);
local rText = HealBot_ScanTooltip_Lines_Right[lineNum];
if not rText then
rText = getglobal("HealBot_ScanTooltipTextRight"..lineNum);
HealBot_ScanTooltip_Lines_Right[lineNum] = rText;
end
if rText and rText:IsVisible() and rText:GetText() then
local txt = rText:GetText();
local t1, t2, match;
+2 -2
View File
@@ -250,7 +250,7 @@ function HealBot_Model:PreserveStateByGUID()
end
local targetIcons = self.units[targetUnit].icons
if not targetIcons then targetIcons = {} end
if not targetIcons then targetIcons = HealBot_GetTable() end
for k in pairs(targetIcons) do targetIcons[k] = nil end
for k in pairs(self.units[targetUnit]) do self.units[targetUnit][k] = nil end
@@ -263,7 +263,7 @@ function HealBot_Model:PreserveStateByGUID()
self.units[targetUnit].icons = targetIcons
if HealBot_UnitIcons and iconSwaps[targetUnit] then
if not HealBot_UnitIcons[targetUnit] then HealBot_UnitIcons[targetUnit] = {} end
if not HealBot_UnitIcons[targetUnit] then HealBot_UnitIcons[targetUnit] = HealBot_GetTable() end
for j=1, 10 do
HealBot_UnitIcons[targetUnit][j] = iconSwaps[targetUnit][j]
end
+4 -2
View File
@@ -857,8 +857,10 @@ function HealBot_Action_PartyChanged()
if i == last then break end
end
else
local petUnits = { "pet", "partypet1", "partypet2", "partypet3", "partypet4" };
for _, unit in ipairs(petUnits) do
if not HealBot_PetUnits then
HealBot_PetUnits = { "pet", "partypet1", "partypet2", "partypet3", "partypet4" };
end
for _, unit in ipairs(HealBot_PetUnits) do
if not HealBot_Action_UnitButtons[unit] and HealBot_MayHeal(unit) then
i = i + 1;
HealBot_Action_SetHealButton(i, unit);