mirror of
https://github.com/falcosecurity/falco.git
synced 2025-08-13 11:55:50 +00:00
Optimization: don't nest at every boolean op
This commit is contained in:
parent
bbcedef54a
commit
aa31d0a0fb
@ -36,15 +36,25 @@ end
|
||||
--[[
|
||||
Take a filter AST and set it up in the libsinsp runtime, using the filter API.
|
||||
--]]
|
||||
local function install_filter(node)
|
||||
local function install_filter(node, parent_bool_op)
|
||||
local t = node.type
|
||||
|
||||
if t == "BinaryBoolOp" then
|
||||
filter.nest() --io.write("(")
|
||||
install_filter(node.left)
|
||||
filter.bool_op(node.operator) --io.write(" "..node.operator.." ")
|
||||
install_filter(node.right)
|
||||
filter.unnest() --io.write(")")
|
||||
|
||||
-- "nesting" (the runtime equivalent of placing parens in syntax) is
|
||||
-- never necessary when we have identical successive operators. so we
|
||||
-- avoid it as a runtime performance optimization.
|
||||
if (not(node.operator == parent_bool_op)) then
|
||||
filter.nest() -- io.write("(")
|
||||
end
|
||||
|
||||
install_filter(node.left, node.operator)
|
||||
filter.bool_op(node.operator) -- io.write(" "..node.operator.." ")
|
||||
install_filter(node.right, node.operator)
|
||||
|
||||
if (not (node.operator == parent_bool_op)) then
|
||||
filter.unnest() -- io.write(")")
|
||||
end
|
||||
|
||||
elseif t == "UnaryBoolOp" then
|
||||
filter.nest() --io.write("(")
|
||||
@ -135,6 +145,7 @@ end
|
||||
|
||||
function on_done()
|
||||
install_filter(state.filter_ast)
|
||||
io.flush()
|
||||
end
|
||||
|
||||
evt = nil
|
||||
|
Loading…
Reference in New Issue
Block a user