Skip to content

Commit

Permalink
Make some micro-optimizations to tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
haste committed Oct 11, 2010
1 parent 4c0239b commit 88e23e6
Showing 1 changed file with 62 additions and 9 deletions.
71 changes: 62 additions & 9 deletions elements/tags.lua
Expand Up @@ -470,7 +470,7 @@ local Tag = function(self, fs, tagstr)

local func = tagPool[tagstr]
if(not func) then
local format = tagstr:gsub('%%', '%%%%'):gsub(_PATTERN, '%%s')
local format, numTags = tagstr:gsub('%%', '%%%%'):gsub(_PATTERN, '%%s')
local args = {}

for bracket in tagstr:gmatch(_PATTERN) do
Expand Down Expand Up @@ -524,17 +524,70 @@ local Tag = function(self, fs, tagstr)
end
end

func = function(self)
local unit = self.parent.unit
local __unit = self.parent.realUnit
local overrideUnit = self.overrideUnit
if(numTags == 1) then
func = function(self)
local parent = self.parent
local realUnit
if(self.overrideUnit) then
realUnit = parent.realUnit
end

_ENV._COLORS = parent.colors
return self:SetFormattedText(
format,
args[1](parent.unit, realUnit) or ''
)
end
elseif(numTags == 2) then
func = function(self)
local parent = self.parent
local unit = parent.unit
local realUnit
if(self.overrideUnit) then
realUnit = parent.realUnit
end

_ENV._COLORS = parent.colors
return self:SetFormattedText(
format,
args[1](unit, realUnit) or '',
args[2](unit, realUnit) or ''
)
end
elseif(numTags == 3) then
func = function(self)
local parent = self.parent
local unit = parent.unit
local realUnit
if(self.overrideUnit) then
realUnit = parent.realUnit
end

_ENV._COLORS = self.parent.colors
for i, func in next, args do
tmp[i] = func(unit, overrideUnit and __unit) or ''
_ENV._COLORS = parent.colors
return self:SetFormattedText(
format,
args[1](unit, realUnit) or '',
args[2](unit, realUnit) or '',
args[3](unit, realUnit) or ''
)
end
else
func = function(self)
local parent = self.parent
local unit = parent.unit
local realUnit
if(self.overrideUnit) then
realUnit = parent.realUnit
end

self:SetFormattedText(format, unpack(tmp))
_ENV._COLORS = parent.colors
for i, func in next, args do
tmp[i] = func(unit, realUnit) or ''
end

-- We do 1, numTags because tmp can hold several unneeded variables.
return self:SetFormattedText(format, unpack(tmp, 1, numTags))
end
end

tagPool[tagstr] = func
Expand Down

0 comments on commit 88e23e6

Please sign in to comment.