special case strip(call_move) to stripmove()

this gets called so much the extra function overhead actually seems bad
This commit is contained in:
2025-06-21 14:55:20 -07:00
parent 99323be298
commit 6d6e13cf3b

View File

@ -107,6 +107,22 @@ function linked_list:strip(f)
self.tail = p self.tail = p
end end
-- stripmove calls x:move() for
-- each node, removing each node
-- for which x:move() is true.
function linked_list:stripmove()
local p, n = self, self.next
while n do
if n:move() then
p.next = n.next
else
p = n
end
n = n.next
end
self.tail = p
end
-- optimized special case - -- optimized special case -
-- could be done with strip but -- could be done with strip but
-- this avoids extra function -- this avoids extra function
@ -185,14 +201,6 @@ function _update60()
mode:update() mode:update()
end end
function call_f(x)
return x:f()
end
function call_move(x)
return x:move()
end
function ones(n) function ones(n)
local ret = 0 local ret = 0
while n != 0 do while n != 0 do
@ -233,9 +241,8 @@ function updategame()
current_wave:load(0, 0, min(ones(waves_complete)\2, 4)) current_wave:load(0, 0, min(ones(waves_complete)\2, 4))
end end
events:vore(new_events) events:vore(new_events)
events:strip(call_move) for _, lst in ipairs{events, intangibles_bg, eships} do
for _, lst in ipairs{intangibles_bg, eships} do lst:stripmove()
lst:strip(call_move)
end end
-- eship collider will be used -- eship collider will be used
@ -257,7 +264,7 @@ function updategame()
return eb:hitship(ps) return eb:hitship(ps)
end) end)
else else
ebullets:strip(call_move) ebullets:stripmove()
end end
pbullets:strip(function(pb) pbullets:strip(function(pb)
@ -268,7 +275,7 @@ function updategame()
end end
end) end)
intangibles_fg:strip(call_move) intangibles_fg:stripmove()
if waves_complete == 32767 and not eships.next and not ebullets.next and not events.next then if waves_complete == 32767 and not eships.next and not ebullets.next and not events.next then
game_state = win game_state = win