Skip to content

Commit

Permalink
Use strsplit instead of match for GUID->ID
Browse files Browse the repository at this point in the history
The thinking is this will be faster than using the match method.

Also refactors the GUIDToID method in the Tools table to be a regular
function instead, to hopefully get some better performance in CLEU.
  • Loading branch information
Sharparam committed Aug 20, 2024
1 parent 4f64612 commit c5e07b3
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ stds.wow = {
"Settings",
"SOUNDKIT",
"StaticPopup_Show",
"strsplit",
"time",
"TooltipDataProcessor",
"UIParent",
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"math",
"Settings",
"SOUNDKIT",
"strsplit",
"IsInRaid",
"IsInGroup",
"UnitXPMax",
Expand Down
2 changes: 1 addition & 1 deletion Command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ end)

C:Register({"target", "t", "tar"}, function()
if not UnitExists("target") or UnitIsPlayer("target") then return end
local id = KTT:GUIDToID(UnitGUID("target"))
local id = KTT.GUIDToID(UnitGUID("target"))
KT:PrintKills(id)
end)

Expand Down
7 changes: 5 additions & 2 deletions KillTrack.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ local ET

local KTT = KT.Tools

-- Upvalue as it's used in CLEU
local GUIDToID = KTT.GUIDToID

local FirstDamage = {} -- Tracks first damage to a mob registered by CLEU
local LastDamage = {} -- Tracks whoever did the most recent damage to a mob
local DamageValid = {} -- Determines if mob is tapped by player/group
Expand Down Expand Up @@ -222,7 +225,7 @@ function KT.Events.COMBAT_LOG_EVENT_UNFILTERED(self)
if event ~= "UNIT_DIED" then return end

-- Perform solo/group checks
local d_id = KTT:GUIDToID(d_guid)
local d_id = GUIDToID(d_guid)
local firstDamage = FirstDamage[d_guid]
local lastDamage = LastDamage[d_guid]
local firstByPlayer = firstDamage == self.PlayerGUID or firstDamage == UnitGUID("pet")
Expand Down Expand Up @@ -282,7 +285,7 @@ local function tooltip_enhancer(self)
local _, unit = self:GetUnit()
if not unit then return end
if UnitIsPlayer(unit) then return end
local id = KTT:GUIDToID(UnitGUID(unit))
local id = KTT.GUIDToID(UnitGUID(unit))
if not id then return end
if UnitCanAttack("player", unit) then
local mob, charMob = KT:InitMob(id, UnitName(unit))
Expand Down
2 changes: 1 addition & 1 deletion Options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function Opt:Show()
local showTarget = button("Target", "Show information about the currently selected target",
function()
if not UnitExists("target") or UnitIsPlayer("target") then return end
local id = KTT:GUIDToID(UnitGUID("target"))
local id = KTT.GUIDToID(UnitGUID("target"))
KT:PrintKills(id)
end)
showTarget:SetWidth(150)
Expand Down
6 changes: 4 additions & 2 deletions Tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ end
-- OTHER TOOLS --
-----------------

function KTT:GUIDToID(guid)
local ssplit = strsplit
function KTT.GUIDToID(guid)
if not guid then return nil end
local id = guid:match("^%w+%-0%-%d+%-%d+%-%d+%-(%d+)%-[A-Z%d]+$")
-- local id = guid:match("^%w+%-0%-%d+%-%d+%-%d+%-(%d+)%-[A-Z%d]+$")
local _, _, _, _, _, id = ssplit("-", guid)
return tonumber(id)
end

0 comments on commit c5e07b3

Please sign in to comment.