compiler: pre-inline layout info for known builtin types

This makes the layout code a bit bigger in size as the inlined version
is constructing struct from constant, but let the slint compiler "see"
though more code and allow to optimize away many layout related properties

Before this change

cargo run -p slint-compiler -- examples/printerdemo_mcu/ui/printerdemo.slint -f rust | rustfmt | wc
  38873   83654 1925830
cargo run -p slint-compiler -- examples/gallery/gallery.slint -f rust | rustfmt | wc
  103817  224874 5316553

After the this change

cargo run -p slint-compiler -- examples/printerdemo_mcu/ui/printerdemo.slint -f rust | rustfmt | wc
  38643   84506 1925846
cargo run -p slint-compiler -- examples/gallery/gallery.slint -f rust | rustfmt | wc
 103210  224427 5291034
This commit is contained in:
Olivier Goffart 2023-10-12 11:22:07 +02:00 committed by Olivier Goffart
parent 762c21890c
commit e023335f83

View file

@ -519,7 +519,17 @@ pub fn implicit_layout_info_call(elem: &ElementRc, orientation: Orientation) ->
}
}
ElementType::Builtin(base_type)
if matches!(base_type.name.as_str(), "Rectangle" | "Empty") =>
if matches!(
base_type.name.as_str(),
"Rectangle"
| "Empty"
| "TouchArea"
| "FocusScope"
| "Opacity"
| "Layer"
| "BoxShadow"
| "Clip"
) =>
{
// hard-code the value for rectangle because many rectangle end up optimized away and we
// don't want to depend on the element.