Skip to content

Commit

Permalink
refactor: perform table comparisson in a single call
Browse files Browse the repository at this point in the history
  • Loading branch information
Rainrider committed Apr 21, 2022
1 parent 53fa5b0 commit 3588578
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions oUF_Dispellable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,19 @@ local function ToggleElement(enable)
end
end

local function AreTablesEqual(a, b)
-- shallow comparison of primitive key/value types
local function TablesMatch(a, b)
for k, v in next, a do
if b[k] ~= v then
return false
end
end
for k, v in next, b do
if a[k] ~= v then
return false
end
end

return true
end

Expand All @@ -376,10 +383,7 @@ local function UpdateDispels()
end

if next(available) then
local areEqual = AreTablesEqual(available, canDispel)
areEqual = areEqual and AreTablesEqual(canDispel, available)

if not areEqual then
if not TablesMatch(available, canDispel) then
wipe(canDispel)
for debuffType in next, available do
canDispel[debuffType] = available[debuffType]
Expand Down

0 comments on commit 3588578

Please sign in to comment.