mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 18:58:36 +00:00
Cache the reserved properties in a hash map for reserved_property()
The latter accumulates ~2.6% of all CPU cycles, Now, it only takes 1.3% by using the hash map here.
This commit is contained in:
parent
0abfb056a1
commit
00dec34d34
1 changed files with 15 additions and 11 deletions
|
@ -177,17 +177,21 @@ pub fn reserved_properties() -> impl Iterator<Item = (&'static str, Type, Proper
|
|||
|
||||
/// lookup reserved property injected in every item
|
||||
pub fn reserved_property(name: &str) -> PropertyLookupResult {
|
||||
for (p, t, property_visibility) in reserved_properties() {
|
||||
if p == name {
|
||||
return PropertyLookupResult {
|
||||
property_type: t,
|
||||
resolved_name: name.into(),
|
||||
is_local_to_component: false,
|
||||
is_in_direct_base: false,
|
||||
property_visibility,
|
||||
declared_pure: None,
|
||||
};
|
||||
}
|
||||
thread_local! {
|
||||
static RESERVED_PROPERTIES: HashMap<&'static str, (Type, PropertyVisibility)>
|
||||
= reserved_properties().map(|(name, ty, visibility)| (name, (ty, visibility))).collect();
|
||||
}
|
||||
if let Some(result) = RESERVED_PROPERTIES.with(|reserved| {
|
||||
reserved.get(name).map(|(ty, visibility)| PropertyLookupResult {
|
||||
property_type: ty.clone(),
|
||||
resolved_name: name.into(),
|
||||
is_local_to_component: false,
|
||||
is_in_direct_base: false,
|
||||
property_visibility: *visibility,
|
||||
declared_pure: None,
|
||||
})
|
||||
}) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Report deprecated known reserved properties (maximum_width, minimum_height, ...)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue