Skip to content

Commit

Permalink
Caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Kkthnx committed Nov 17, 2024
1 parent 2bac834 commit c6976cc
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 37 deletions.
19 changes: 19 additions & 0 deletions KkthnxUI/Developer/Core.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
local K, C, L = KkthnxUI[1], KkthnxUI[2], KkthnxUI[3]
local Module = K:NewModule("Developer")

-- Benchmarking global vs. cached access in WoW Lua
local _G = _G
_G.fake1 = 42 -- Set up a global variable

-- Case 1: Direct global access
local start_time = debugprofilestop()
for i = 1, 1e7 do
local temp = _G.fake1
end
print("Global access:", debugprofilestop() - start_time, "ms")

-- Case 2: Cached access
local fake1 = _G.fake1
start_time = debugprofilestop()
for i = 1, 1e7 do
local temp = fake1
end
print("Cached access:", debugprofilestop() - start_time, "ms")

K.Devs = {
["Kkthnx-Area 52"] = true,
["Kkthnx-Valdrakken"] = true,
Expand Down
8 changes: 7 additions & 1 deletion KkthnxUI/Modules/ActionBars/ButtonStyle.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
local K = KkthnxUI[1]
local Module = K:GetModule("ActionBar")

-- Importing required functions and constants
-- WoW API
local CreateFrame = CreateFrame

-- Lua functions
local gsub = string.gsub
local ipairs = ipairs

-- Constants
local KEY_BUTTON4, KEY_NUMPAD1, RANGE_INDICATOR = KEY_BUTTON4, KEY_NUMPAD1, RANGE_INDICATOR

-- Processing key strings
Expand Down
7 changes: 4 additions & 3 deletions KkthnxUI/Modules/ActionBars/Cooldown.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
local K, C = KkthnxUI[1], KkthnxUI[2]
local Module = K:NewModule("Cooldown")

-- Importing required functions
local pairs, format, floor, strfind = pairs, format, floor, strfind
local GetTime, GetActionCooldown, tonumber = GetTime, GetActionCooldown, tonumber
-- Localizing global functions and constants
local _G = _G
local pairs, format, floor, strfind = pairs, string.format, math.floor, string.find
local GetTime, GetActionCooldown, tonumber = _G.GetTime, _G.GetActionCooldown, tonumber

-- Constants for cooldown display
local FONT_SIZE = 19
Expand Down
20 changes: 12 additions & 8 deletions KkthnxUI/Modules/ActionBars/Elements/Bars.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
local K, C = KkthnxUI[1], KkthnxUI[2]
local Module = K:NewModule("ActionBar")

-- Global references for convenience and performance
-- Cache global references
local _G = _G
local UIParent = UIParent
local GetVehicleBarIndex = GetVehicleBarIndex
local UnitExists = UnitExists
local VehicleExit = VehicleExit
local PetDismiss = PetDismiss
local tinsert = table.insert
local RegisterStateDriver = RegisterStateDriver
local UIParent = _G.UIParent
local GetVehicleBarIndex = _G.GetVehicleBarIndex
local UnitExists = _G.UnitExists
local VehicleExit = _G.VehicleExit
local PetDismiss = _G.PetDismiss
local tinsert = _G.table.insert
local RegisterStateDriver = _G.RegisterStateDriver
local ceil = _G.math.ceil
local min = _G.math.min
local select = _G.select
local GetCVarBool = _G.GetCVarBool

-- Layout constants
local margin, padding = 6, 0
Expand Down
10 changes: 9 additions & 1 deletion KkthnxUI/Modules/ActionBars/Elements/Extrabar.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
local K = KkthnxUI[1]
local Module = K:GetModule("ActionBar")

local tinsert = tinsert
-- Cache global references
local _G = _G
local CreateFrame = _G.CreateFrame
local UIParent = _G.UIParent
local tinsert = _G.table.insert
local RegisterStateDriver = _G.RegisterStateDriver
local hooksecurefunc = _G.hooksecurefunc
local IsUsableAction = _G.IsUsableAction

local padding = 0

function Module:CreateExtrabar()
Expand Down
7 changes: 7 additions & 0 deletions KkthnxUI/Modules/ActionBars/Fader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ local Module = K:GetModule("ActionBar")

-- Credit: ElvUI

-- Localizing global functions and constants
local _G = _G
local pairs, ipairs, next = pairs, ipairs, next
local UnitAffectingCombat, UnitExists, UnitHealth, UnitHealthMax = _G.UnitAffectingCombat, _G.UnitExists, _G.UnitHealth, _G.UnitHealthMax
local UnitCastingInfo, UnitChannelInfo, UnitHasVehicleUI = _G.UnitCastingInfo, _G.UnitChannelInfo, _G.UnitHasVehicleUI
local CreateFrame, C_Timer = _G.CreateFrame, _G.C_Timer

local fadeParent
Module.handledbuttons = {}

Expand Down
52 changes: 28 additions & 24 deletions KkthnxUI/Modules/ActionBars/Keybind.lua
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
local K, L = KkthnxUI[1], KkthnxUI[3]
local Module = K:GetModule("ActionBar")

local C_SpellBook_GetSpellBookItemName = C_SpellBook.GetSpellBookItemName
local CreateFrame = CreateFrame
local GameTooltip = GameTooltip
local GetBindingKey = GetBindingKey
local GetBindingName = GetBindingName
local GetMacroInfo = GetMacroInfo
local InCombatLockdown = InCombatLockdown
local IsAltKeyDown = IsAltKeyDown
local IsControlKeyDown = IsControlKeyDown
local IsShiftKeyDown = IsShiftKeyDown
local LoadBindings = LoadBindings
local MAX_ACCOUNT_MACROS = MAX_ACCOUNT_MACROS
local NOT_BOUND = NOT_BOUND
local PRESS_KEY_TO_BIND = PRESS_KEY_TO_BIND
local SaveBindings = SaveBindings
local SetBinding = SetBinding
local SpellBook_GetSpellBookSlot = SpellBook_GetSpellBookSlot
local UIErrorsFrame = UIErrorsFrame
local format = format
local hooksecurefunc = hooksecurefunc
local strfind = strfind
local strupper = strupper
local tonumber = tonumber
-- Cache global functions and constants
local _G = _G
local C_SpellBook_GetSpellBookItemName = _G.C_SpellBook.GetSpellBookItemName
local CreateFrame = _G.CreateFrame
local GameTooltip = _G.GameTooltip
local GetBindingKey = _G.GetBindingKey
local GetBindingName = _G.GetBindingName
local GetMacroInfo = _G.GetMacroInfo
local InCombatLockdown = _G.InCombatLockdown
local IsAltKeyDown = _G.IsAltKeyDown
local IsControlKeyDown = _G.IsControlKeyDown
local IsShiftKeyDown = _G.IsShiftKeyDown
local LoadBindings = _G.LoadBindings
local MAX_ACCOUNT_MACROS = _G.MAX_ACCOUNT_MACROS
local NOT_BOUND = _G.NOT_BOUND
local PRESS_KEY_TO_BIND = _G.PRESS_KEY_TO_BIND
local SaveBindings = _G.SaveBindings
local SetBinding = _G.SetBinding
local SpellBook_GetSpellBookSlot = _G.SpellBook_GetSpellBookSlot
local UIErrorsFrame = _G.UIErrorsFrame
local format = _G.format
local hooksecurefunc = _G.hooksecurefunc
local strfind = _G.strfind
local strupper = _G.strupper
local tonumber = _G.tonumber
local Enum = _G.Enum
local C_AddOns = _G.C_AddOns

-- Button types
local function hookActionButton(self)
Expand Down Expand Up @@ -148,7 +152,7 @@ function Module:Bind_Update(button, spellmacro)

if spellmacro == "SPELL" then
frame.id = SpellBook_GetSpellBookSlot(button)
frame.name = C_SpellBook.GetSpellBookItemName(frame.id, Enum.SpellBookSpellBank.Player)
frame.name = C_SpellBook_GetSpellBookItemName(frame.id, Enum.SpellBookSpellBank.Player)
frame.bindings = { GetBindingKey(spellmacro .. " " .. frame.name) }
elseif spellmacro == "MACRO" then
frame.id = button.selectionIndex or button:GetID()
Expand Down

0 comments on commit c6976cc

Please sign in to comment.