Add predicate memoization to `command.get_all_valid`

This commit is contained in:
Guldoman 2022-08-14 02:15:05 +02:00
parent 06b9953777
commit d944bd85ec
No known key found for this signature in database
GPG Key ID: EA928C8BDA1A8825
1 changed files with 5 additions and 1 deletions

View File

@ -62,8 +62,12 @@ end
function command.get_all_valid()
local res = {}
local memoized_predicates = {}
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)
end
end