mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 02:39:28 +00:00
Also wrap langtype::Type::Struct in an Rc
This makes copying such types much cheaper and will allow us to intern common struct types in the future too. This further drops the sample cost for langtype.rs from ~6.6% down to 4.0%. We are now also able to share/intern common struct types. Before: ``` Time (mean ± σ): 1.073 s ± 0.021 s [User: 0.759 s, System: 0.215 s] Range (min … max): 1.034 s … 1.105 s 10 runs allocations: 3074261 ``` After: ``` Time (mean ± σ): 1.034 s ± 0.026 s [User: 0.733 s, System: 0.201 s] Range (min … max): 1.000 s … 1.078 s 10 runs allocations: 2917476 ```
This commit is contained in:
parent
efdecf0a13
commit
69c68b22b2
29 changed files with 302 additions and 259 deletions
|
@ -11,7 +11,8 @@ use crate::diagnostics::{BuildDiagnostics, SourceLocation, Spanned};
|
|||
use crate::expression_tree::{self, BindingExpression, Expression, Unit};
|
||||
use crate::langtype::EnumerationValue;
|
||||
use crate::langtype::{
|
||||
BuiltinElement, BuiltinPropertyDefault, Callback, Enumeration, Function, NativeClass, Type,
|
||||
BuiltinElement, BuiltinPropertyDefault, Callback, Enumeration, Function, NativeClass, Struct,
|
||||
Type,
|
||||
};
|
||||
use crate::langtype::{ElementType, PropertyLookupResult};
|
||||
use crate::layout::{LayoutConstraints, Orientation};
|
||||
|
@ -90,14 +91,14 @@ impl Document {
|
|||
local_registry: &mut TypeRegister,
|
||||
inner_types: &mut Vec<Type>| {
|
||||
let rust_attributes = n.AtRustAttr().map(|child| vec![child.text().to_smolstr()]);
|
||||
let mut ty =
|
||||
type_struct_from_node(n.ObjectType(), diag, local_registry, rust_attributes);
|
||||
if let Type::Struct { name, .. } = &mut ty {
|
||||
*name = parser::identifier_text(&n.DeclaredIdentifier());
|
||||
} else {
|
||||
assert!(diag.has_errors());
|
||||
return;
|
||||
}
|
||||
let ty = type_struct_from_node(
|
||||
n.ObjectType(),
|
||||
diag,
|
||||
local_registry,
|
||||
rust_attributes,
|
||||
parser::identifier_text(&n.DeclaredIdentifier()),
|
||||
);
|
||||
assert!(matches!(ty, Type::Struct(_)));
|
||||
local_registry.insert_type(ty.clone());
|
||||
inner_types.push(ty);
|
||||
};
|
||||
|
@ -1882,7 +1883,7 @@ pub fn type_from_node(
|
|||
}
|
||||
prop_type
|
||||
} else if let Some(object_node) = node.ObjectType() {
|
||||
type_struct_from_node(object_node, diag, tr, None)
|
||||
type_struct_from_node(object_node, diag, tr, None, None)
|
||||
} else if let Some(array_node) = node.ArrayType() {
|
||||
Type::Array(Box::new(type_from_node(array_node.Type(), diag, tr)))
|
||||
} else {
|
||||
|
@ -1897,6 +1898,7 @@ pub fn type_struct_from_node(
|
|||
diag: &mut BuildDiagnostics,
|
||||
tr: &TypeRegister,
|
||||
rust_attributes: Option<Vec<SmolStr>>,
|
||||
name: Option<SmolStr>,
|
||||
) -> Type {
|
||||
let fields = object_node
|
||||
.ObjectTypeMember()
|
||||
|
@ -1907,7 +1909,7 @@ pub fn type_struct_from_node(
|
|||
)
|
||||
})
|
||||
.collect();
|
||||
Type::Struct { fields, name: None, node: Some(object_node), rust_attributes }
|
||||
Type::Struct(Rc::new(Struct { fields, name, node: Some(object_node), rust_attributes }))
|
||||
}
|
||||
|
||||
fn animation_element_from_node(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue