mirror of
https://github.com/falcosecurity/falco.git
synced 2025-08-14 20:33:31 +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.
|
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
|
local t = node.type
|
||||||
|
|
||||||
if t == "BinaryBoolOp" then
|
if t == "BinaryBoolOp" then
|
||||||
|
|
||||||
|
-- "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("(")
|
filter.nest() -- io.write("(")
|
||||||
install_filter(node.left)
|
end
|
||||||
|
|
||||||
|
install_filter(node.left, node.operator)
|
||||||
filter.bool_op(node.operator) -- io.write(" "..node.operator.." ")
|
filter.bool_op(node.operator) -- io.write(" "..node.operator.." ")
|
||||||
install_filter(node.right)
|
install_filter(node.right, node.operator)
|
||||||
|
|
||||||
|
if (not (node.operator == parent_bool_op)) then
|
||||||
filter.unnest() -- io.write(")")
|
filter.unnest() -- io.write(")")
|
||||||
|
end
|
||||||
|
|
||||||
elseif t == "UnaryBoolOp" then
|
elseif t == "UnaryBoolOp" then
|
||||||
filter.nest() --io.write("(")
|
filter.nest() --io.write("(")
|
||||||
@ -135,6 +145,7 @@ end
|
|||||||
|
|
||||||
function on_done()
|
function on_done()
|
||||||
install_filter(state.filter_ast)
|
install_filter(state.filter_ast)
|
||||||
|
io.flush()
|
||||||
end
|
end
|
||||||
|
|
||||||
evt = nil
|
evt = nil
|
||||||
|
Loading…
Reference in New Issue
Block a user