mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-03 02:13:21 +00:00

This removes a lot of allocations and speeds up the compiler step a bit. Sadly, this patch is very invasive as it touches a lot of files. That said, each individual hunk is pretty trivial. For a non-trivial real-world example, the impact is significant, we get rid of ~29% of all allocations and improve the runtime by about 4.8% (measured until the viewer loop would start). Before: ``` Benchmark 1: ./target/release/slint-viewer ../slint-perf/app.slint Time (mean ± σ): 664.2 ms ± 6.7 ms [User: 589.2 ms, System: 74.0 ms] Range (min … max): 659.0 ms … 682.4 ms 10 runs allocations: 4886888 temporary allocations: 857508 ``` After: ``` Benchmark 1: ./target/release/slint-viewer ../slint-perf/app.slint Time (mean ± σ): 639.5 ms ± 17.8 ms [User: 556.9 ms, System: 76.2 ms] Range (min … max): 621.4 ms … 666.5 ms 10 runs allocations: 3544318 temporary allocations: 495685 ```
40 lines
1.6 KiB
Rust
40 lines
1.6 KiB
Rust
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
|
|
|
//! Pass that applies the default border-radius to border-top|bottom-left|right-radius.
|
|
|
|
use crate::diagnostics::BuildDiagnostics;
|
|
use crate::expression_tree::{Expression, NamedReference};
|
|
use crate::object_tree::Component;
|
|
use smol_str::SmolStr;
|
|
use std::rc::Rc;
|
|
|
|
pub const BORDER_RADIUS_PROPERTIES: [&str; 4] = [
|
|
"border-top-left-radius",
|
|
"border-top-right-radius",
|
|
"border-bottom-right-radius",
|
|
"border-bottom-left-radius",
|
|
];
|
|
|
|
pub fn handle_border_radius(root_component: &Rc<Component>, _diag: &mut BuildDiagnostics) {
|
|
crate::object_tree::recurse_elem_including_sub_components_no_borrow(
|
|
root_component,
|
|
&(),
|
|
&mut |elem, _| {
|
|
let bty = if let Some(bty) = elem.borrow().builtin_type() { bty } else { return };
|
|
if bty.name == "Rectangle"
|
|
&& elem.borrow().is_binding_set("border-radius", true)
|
|
&& BORDER_RADIUS_PROPERTIES
|
|
.iter()
|
|
.any(|property_name| elem.borrow().is_binding_set(property_name, true))
|
|
{
|
|
let border_radius = NamedReference::new(elem, "border-radius");
|
|
for property_name in BORDER_RADIUS_PROPERTIES.iter() {
|
|
elem.borrow_mut().set_binding_if_not_set(SmolStr::new(property_name), || {
|
|
Expression::PropertyReference(border_radius.clone())
|
|
});
|
|
}
|
|
}
|
|
},
|
|
)
|
|
}
|