Add predicate memoization to `command.get_all_valid`
This commit is contained in:
parent
06b9953777
commit
d944bd85ec
|
@ -62,8 +62,12 @@ end
|
||||||
|
|
||||||
function command.get_all_valid()
|
function command.get_all_valid()
|
||||||
local res = {}
|
local res = {}
|
||||||
|
local memoized_predicates = {}
|
||||||
for name, cmd in pairs(command.map) do
|
for name, cmd in pairs(command.map) do
|
||||||
if cmd.predicate() then
|
if memoized_predicates[cmd.predicate] == nil then
|
||||||
|
memoized_predicates[cmd.predicate] = cmd.predicate()
|
||||||
|
end
|
||||||
|
if memoized_predicates[cmd.predicate] then
|
||||||
table.insert(res, name)
|
table.insert(res, name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue