Quantcast WoWInterface - View Single Post - oUF_Layout optimization
View Single Post
12-11-14, 10:39 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Tags:
Code:
return format('|cff%02x%02x%02x%s', r, g, 0, healthcurrent)
Very minor, but there's no need to spend CPU time turning that 0 into 00 over and over; just hardcode the 00:
Code:
return format('|cff%02x%02x00%s', r, g, healthcurrent)
You could even take that further and avoid that second format call entirely:
Code:
        local color
        if healthcurrent < healthmax then
                color = '|cffb40000'
        else
                color = '|cff00b400'
        end
        if healthcurrent >= 1000000 then
                healthcurrent = format('%.1fm', healthcurrent/1000000)
        elseif healthcurrent >= 1000 then
                healthcurrent = format('%.0fk', healthcurrent/1000)
        end
        return color .. healthcurrent
================================
Code:
powertype = select(2,UnitPowerType(u))
select is a complete waste of CPU time in 99.9999999999999999% of situations, including this one. Use a throwaway variable instead:
Code:
local powercurrent, powertype, pr, pg, pb, _
_, powertype = UnitPowerType(u)
...or just the less intuitive but equally effective method of overwriting the variable with itself:
Code:
powertype, powertype = UnitPowerType(u)
================================
Code:
                elseif powertype == 'FOCUS' then
                        pr, pg, pb = 255, 128, 65
                elseif powertype == 'ENERGY' then
                        pr, pg, pb = 255, 255, 0
                elseif powertype == 'RUNIC_POWER' then
                        pr, pg, pb = 0, 209, 255
                else
                        pr, pg, pb = 255, 0, 0
                end
In all these cases, those are the default colors for those power types, so rather than a list of "elseif" conditions and hardcoded values, just fetch the default colors:
Code:
                else
                        local c = PowerBarColor[powertype]
                        pr, pg, pb = c.r * 255, c*g * 255, c*b * 255
                end
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
  Reply With Quote