Reduce table lookups

This commit is contained in:
Robin 2021-01-16 02:06:40 +01:00
parent 0ab1124cd8
commit 33ca2dc0fa
4 changed files with 23 additions and 16 deletions

View File

@ -32,12 +32,13 @@ local function scanAllBags(delayed)
if(not addon:funcSync(scanAllBags,delayed)) then return end
local playerID = addon.getPID()
if(playerID) then
local tab = modul['db'][playerID]
for bag=0,4 do
modul['db'][playerID][bag] = addon:scanBag(bag) -- loop all bought bags
tab[bag] = addon:scanBag(bag) -- loop all bought bags
end
for k,v in pairs(modul['db'][playerID]) do
if(k<0 or k>4) then
modul['db'][playerID][k] = nil -- prevent bogus bags
tab[k] = nil -- prevent bogus bags
end
end
end

View File

@ -13,14 +13,16 @@ function modul.Guess(id)
if(playerID and dbcount > count) then
local dif = dbcount - count
modul['db'][playerID] = modul['db'][playerID] or {}
local tab = modul['db'][playerID]
for bag=5,GetNumBankSlots()+4 do
if(modul['db'][playerID][bag] and modul['db'][playerID][bag][id] and modul['db'][playerID][bag][id]['count']>0) then
while(dif>0 and modul['db'][playerID][bag][id]['count']>0) do
local btab = tab[bag]
if(btab and btab[id] and btab[id]['count']>0) then
while(dif>0 and btab[id]['count']>0) do
tt = true
dif = dif - 1
modul['db'][playerID][bag][id]['count'] = modul['db'][playerID][bag][id]['count'] - 1
if(modul['db'][playerID][bag][id]['count'] == 0) then
modul['db'][playerID][bag][id] = nil
btab[id]['count'] = btab[id]['count'] - 1
if(btab[id]['count'] == 0) then
btab[id] = nil
end
end
end
@ -45,22 +47,24 @@ local function scanAllBankBags(delayed)
local playerID = addon.getPID()
if(playerID) then
modul['db'][playerID] = modul['db'][playerID] or {}
local tab = modul['db'][playerID]
for bag=5,GetNumBankSlots()+4 do
local btab = tab[bag]
if(BankIsOpen) then
modul['db'][playerID][bag] = addon:scanBag(bag) -- loop all bought bankbags
btab = addon:scanBag(bag) -- loop all bought bankbags
else
guess(modul['db'][playerID][bag])
guess(tab)
end
end
if(BankIsOpen) then
modul['db'][playerID][-1] = addon:scanBag(-1) -- Main bankbag
tab[-1] = addon:scanBag(-1) -- Main bankbag
else
guess(modul['db'][playerID][-1])
guess(tab[-1])
end
modul['db'][playerID][-3] = addon:scanBag(-3) -- Main reagentbag
tab[-3] = addon:scanBag(-3) -- Main reagentbag
for k,v in pairs(modul['db'][playerID]) do
if(not(k==-1) and not(k==-3) and not(k>4 and k<=GetNumBankSlots()+4)) then
modul['db'][playerID][k] = nil -- prevent bogus bankbags
tab[k] = nil -- prevent bogus bankbags
end
end
addon:updateTT()

View File

@ -71,6 +71,7 @@ function events:CURRENCY_DISPLAY_UPDATE(event)
local playerID = addon.getPID()
if(playerID) then
modul['db'][playerID] = modul['db'][playerID] or {}
local tab = modul['db'][playerID]
for index=1,GetCurrencyListSize() do
local curInfo
if(C_CurrencyInfo and C_CurrencyInfo.GetCurrencyListInfo) then
@ -86,7 +87,7 @@ function events:CURRENCY_DISPLAY_UPDATE(event)
end
local itemID = getCurrencyItem(index)
if((not curInfo['isHeader']) and itemID) then
modul['db'][playerID][tonumber(itemID)] = {
tab[tonumber(itemID)] = {
['count'] = curInfo['quantity'],
['max'] = curInfo['maxQuantity'],
}

View File

@ -23,8 +23,9 @@ local function gbagLoop(id)
res[guildname] = res[guildname] or {
[dName] = 0
}
res[guildname][dName] = res[guildname][dName] or 0
res[guildname][dName] = res[guildname][dName] + b['count']
local tab = res[guildname][dName]
tab = tab or 0
tab = tab + b['count']
end
end
end