Minor performance improvement

It turns out that formspec_ast.find is quite slow, moving the
field_close_on_enter code to the new shorthand elements insertion
improves performance (at least on my rudimentary benchmarks of the
example form) and probably negates the overhead added by the inline
styles/tooltips code.
This commit is contained in:
luk3yx 2024-05-18 19:24:12 +12:00
parent b42a9dc1be
commit 45363ee461

View File

@ -572,14 +572,6 @@ local function render_ast(node, embedded)
node.bg_fullscreen = nil
end
for field in formspec_ast.find(node, 'field') do
res[#res + 1] = {
type = 'field_close_on_enter',
name = field.name,
close_on_enter = false,
}
end
-- Add the root element's background image as a fullscreen one
if node.bgimg and not embedded then
res[#res + 1] = {
@ -998,6 +990,12 @@ local function insert_shorthand_elements(tree)
if node.type == "container" or node.type == "scroll_container" then
insert_shorthand_elements(node)
elseif node.type == "field" then
table.insert(tree, i, {
type = 'field_close_on_enter',
name = field.name,
close_on_enter = false,
})
end
end
end