WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   COMBAT_LOG_EVENT_UNFILTERED improvement help (https://www.wowinterface.com/forums/showthread.php?t=33101)

dr_AllCOM3 06-11-10 06:45 AM

COMBAT_LOG_EVENT_UNFILTERED improvement help
 
I wonder if that code can be improved. It takes up quite some cpu time. Nothing extremely bad, but COMBAT_LOG_EVENT_UNFILTERED is called very often and mostly at bad times.
Thanks in advance for looking through it.


Code:

function addon:COMBAT_LOG_EVENT_UNFILTERED( event, ... )
    --timestamp, eventType, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags
        local _, event  = ...
   
    if addon[event] then
                addon[event]( self, ... )
        end
end

function addon:SPELL_AURA_APPLIED( ... )
    --timestamp, eventType, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags
    local timestamp, eventType, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags = select( 1, ... )
   
    local spellId, spellName, spellSchool, auraType, amount  = select( 9, ... )
   
    if playerGUID==dstGUID or playerTargetGUID==dstGUID then return end -- No auras from player wanted.
   
    local fromPlayer = srcGUID==playerGUID and 1
   
    if auraType=="DEBUFF" then
        auraType = "HARMFUL"
    elseif auraType=="BUFF" then
        auraType = "HELPFUL"
    end
   
    local priority = checkFilter( strlower( spellName ), fromPlayer, auraType )
   
    if priority then
        if global.spellList[spellId] then
            local time = GetTime()
           
            table[dstGUID] = table[dstGUID] or {}
           
            tinsert( guidBuffs[dstGUID], { stuff = stuff, priority = priority, and so on } )
        else
            -- Almost the same
        end
    end
   
    update( dstGUID )
end

local function checkFilter( spellName, fromPlayer, auraType ) -- Filter aura
    local list
    if auraType=="HELPFUL" then
        list = db.buffFilter.buffs
    elseif auraType=="HARMFUL" then
        list = db.buffFilter.debuffs
    else
        return nil
    end
   
    if list.never[spellName] then
        return nil
    elseif fromPlayer and list.my[spellName] then
        return list.my[spellName]
    elseif list.any[spellName] then
        return list.any[spellName]
    elseif fromPlayer and list.allMy then
        return 1
    elseif list.allAny then
        return 1
    else
        return nil
    end
end

There are more like SPELL_AURA_REMOVED and the other SPELL_AURA changes on units, but they're far smaller and have no further checks or filtering.

Waverian 06-11-10 07:02 AM

Quote:

Originally Posted by dr_AllCOM3 (Post 191724)
Code:

            tinsert( guidBuffs[dstGUID], { stuff = stuff, priority = priority, and so

This could get expensive depending on how often the table values are being added & removed. While it's not likely that you'll generate enough tables to have an effect by themselves, if the additional tables don't have a reference (i.e. you removed the value when it was no longer being used) they're going to be garbage collected.

You shouldn't be using varargs in your subevents. The number of arguments returned will always be the same. You'll save a tiny bit of time by not having to use the select function.

You're using strlower to check for keys in all of your list tables. It's not going to make or break the function speed, but you shouldn't do it unless it improves functionality or readability.

I personally don't see any other blatant problems though. I also can't really visualize what you're attempting to do to see if there's an alternative method.

dr_AllCOM3 06-11-10 07:18 AM

The tinsert isn't used very often, that's what the filtering is for :).
Is varargs the ... ? I'll try that, thanks.
strlower is just for convenience. I could remove that and just tell the user to watch out for proper cases.

I'm trying to improve my COMBAT_LOG function, since it uses the vast majority of my addon's CPU time. Maybe there are some tricks or common practices to handle the COMBAT_LOG.


All times are GMT -6. The time now is 05:33 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI