slint/internal/compiler/passes/remove_unused_properties.rs
Tobias Hunger e6b24bceec [reorg]: Set up and populate the internal directory
Move "internal" crates into the `internal` directory. This first batch
includes most of sixtyfps_runtime but leaves the rendering backends
alone for now.

pre-commit applied some cleanups to the moved files:
 - Consistent newline at end of file policy
 - trimming trailing whitespace
 - Formatting Cargo.toml files.
2022-01-31 16:00:50 +01:00

43 lines
1.6 KiB
Rust

// Copyright © SixtyFPS GmbH <info@sixtyfps.io>
// SPDX-License-Identifier: (GPL-3.0-only OR LicenseRef-SixtyFPS-commercial)
//! Remove the properties which are not used
use crate::object_tree::Component;
use std::collections::HashSet;
pub fn remove_unused_properties(component: &Component) {
fn recurse_remove_unused_properties(component: &Component) {
crate::object_tree::recurse_elem_including_sub_components_no_borrow(
component,
&(),
&mut |elem, _| {
let mut to_remove = HashSet::new();
for (prop, decl) in &elem.borrow().property_declarations {
if !decl.expose_in_public_api
&& !elem.borrow().named_references.is_referenced(prop)
&& !elem
.borrow()
.property_analysis
.borrow()
.get(prop)
.map_or(false, |v| v.is_used())
{
to_remove.insert(prop.to_owned());
}
}
let mut elem = elem.borrow_mut();
for x in &to_remove {
elem.property_declarations.remove(x);
elem.property_analysis.borrow_mut().remove(x);
elem.bindings.remove(x);
}
},
);
for global in &component.used_types.borrow().globals {
recurse_remove_unused_properties(global);
}
}
recurse_remove_unused_properties(component)
}