Module:Sprite: Difference between revisions

m Revert edits by MarkusRost (talk): Accidentally broke something
Porting an improvement I implemented on from minecraft-ru
Line 298: Line 298:
end )
end )
-- Reuse the same table in all iterations of the loop to avoid allocating
-- many copies of basically the same table in every iteration.
-- This seems to cut memory usage for the sprite doc by about 7% (tested on
-- minecraft-ru); may not help with worse cases that hit the post-expand
-- limit, or with Module:Documentation memory limits
-- This works because the `base` function does not mutate the args table
-- (which is an anti-pattern anyway, for reasons such as it prevents table
-- reuse optimizations)
local spriteArgs = { pos = 0, data = dataPage, nourl = spriteStyle ~= '' }
for _, data in ipairs( keyedData ) do
for _, data in ipairs( keyedData ) do
local idData = data.data
local idData = data.data
local pos = idData.pos
local pos = idData.pos
spriteArgs.pos = pos
local section = sections[idData.section]
local section = sections[idData.section]
local names = section[pos]
local names = section[pos]
Line 306: Line 316:
local box = section.boxes:tag( 'li' ):addClass( 'spritedoc-box' ):attr( 'data-pos', pos )
local box = section.boxes:tag( 'li' ):addClass( 'spritedoc-box' ):attr( 'data-pos', pos )
box:tag( 'div' ):addClass( 'spritedoc-image' )
box:tag( 'div' ):addClass( 'spritedoc-image' )
:wikitext( p.base{ pos = pos, data = dataPage, nourl = spriteStyle ~= '' } )
:wikitext( p.base(spriteArgs) )
names = box:tag( 'ul' ):addClass( 'spritedoc-names' )
names = box:tag( 'ul' ):addClass( 'spritedoc-names' )