Optimization: improve expression inlining

If a property is only used once, we can inline it with a bigger
threshold.
But this require to first compute the use, and then do the inlining
while adjusting the usages
This commit is contained in:
Olivier Goffart 2024-07-10 18:11:19 +02:00
parent 4de03fba5b
commit 5f77808d1c
7 changed files with 128 additions and 55 deletions

View file

@ -1912,7 +1912,7 @@ fn generate_sub_component(
let mut properties_init_code = Vec::new();
for (prop, expression) in &component.property_init {
if expression.use_count.get() > 0 {
if expression.use_count.get() > 0 && component.prop_used(prop) {
handle_property_init(prop, expression, &mut properties_init_code, &ctx)
}
}

View file

@ -995,22 +995,15 @@ fn generate_sub_component(
}
for (prop, expression) in &component.property_init {
if expression.use_count.get() > 0 {
if expression.use_count.get() > 0 && component.prop_used(prop) {
handle_property_init(prop, expression, &mut init, &ctx)
}
}
for prop in &component.const_properties {
if let llr::PropertyReference::Local { property_index, sub_component_path } = prop {
let mut sc = component;
for i in sub_component_path {
sc = &sc.sub_components[*i].ty;
}
if sc.properties[*property_index].use_count.get() == 0 {
continue;
}
if component.prop_used(prop) {
let rust_property = access_member(prop, &ctx).unwrap();
init.push(quote!(#rust_property.set_constant();))
}
let rust_property = access_member(prop, &ctx).unwrap();
init.push(quote!(#rust_property.set_constant();))
}
let parent_component_type = parent_ctx.iter().map(|parent| {