Skip to content

Commit 6ff8abf

Browse files
milianwogoffart
authored andcommitted
Move thread local types from typeregister into BUILTIN
This way we don't need a separate TLS slot for these two types.
1 parent 6e9e66e commit 6ff8abf

File tree

1 file changed

+41
-39
lines changed

1 file changed

+41
-39
lines changed

internal/compiler/typeregister.rs

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,47 @@ i_slint_common::for_each_enums!(declare_enums);
7979

8080
pub struct BuiltinTypes {
8181
pub enums: BuiltinEnums,
82+
pub noarg_callback_type: Type,
83+
pub strarg_callback_type: Type,
84+
pub logical_point_type: Type,
85+
pub font_metrics_type: Type,
8286
}
8387

8488
impl BuiltinTypes {
8589
fn new() -> Self {
86-
Self { enums: BuiltinEnums::new() }
90+
Self {
91+
enums: BuiltinEnums::new(),
92+
logical_point_type: Type::Struct(Rc::new(Struct {
93+
fields: IntoIterator::into_iter([
94+
(SmolStr::new_static("x"), Type::LogicalLength),
95+
(SmolStr::new_static("y"), Type::LogicalLength),
96+
])
97+
.collect(),
98+
name: Some("slint::LogicalPosition".into()),
99+
node: None,
100+
rust_attributes: None,
101+
})),
102+
font_metrics_type: Type::Struct(Rc::new(Struct {
103+
fields: IntoIterator::into_iter([
104+
(SmolStr::new_static("ascent"), Type::LogicalLength),
105+
(SmolStr::new_static("descent"), Type::LogicalLength),
106+
(SmolStr::new_static("x-height"), Type::LogicalLength),
107+
(SmolStr::new_static("cap-height"), Type::LogicalLength),
108+
])
109+
.collect(),
110+
name: Some("slint::private_api::FontMetrics".into()),
111+
node: None,
112+
rust_attributes: None,
113+
})),
114+
noarg_callback_type: Type::Callback(Rc::new(Callback {
115+
return_type: None,
116+
args: vec![],
117+
})),
118+
strarg_callback_type: Type::Callback(Rc::new(Callback {
119+
return_type: None,
120+
args: vec![Type::String],
121+
})),
122+
}
87123
}
88124
}
89125

@@ -112,19 +148,11 @@ pub const RESERVED_ROTATION_PROPERTIES: &[(&str, Type)] = &[
112148
];
113149

114150
fn noarg_callback_type() -> Type {
115-
thread_local! {
116-
static TYPE: Type = Type::Callback(Rc::new(Callback { return_type: None, args: vec![] }));
117-
}
118-
119-
TYPE.with(|t| t.clone())
151+
BUILTIN.with(|types| types.noarg_callback_type.clone())
120152
}
121153

122154
fn strarg_callback_type() -> Type {
123-
thread_local! {
124-
static TYPE: Type = Type::Callback(Rc::new(Callback { return_type: None, args: vec![Type::String] }));
125-
}
126-
127-
TYPE.with(|t| t.clone())
155+
BUILTIN.with(|types| types.strarg_callback_type.clone())
128156
}
129157

130158
pub fn reserved_accessibility_properties() -> impl Iterator<Item = (&'static str, Type)> {
@@ -599,35 +627,9 @@ impl TypeRegister {
599627
}
600628

601629
pub fn logical_point_type() -> Type {
602-
thread_local! {
603-
static TYPE: Type = Type::Struct(Rc::new(Struct {
604-
fields: IntoIterator::into_iter([
605-
(SmolStr::new_static("x"), Type::LogicalLength),
606-
(SmolStr::new_static("y"), Type::LogicalLength),
607-
])
608-
.collect(),
609-
name: Some("slint::LogicalPosition".into()),
610-
node: None,
611-
rust_attributes: None,
612-
}));
613-
}
614-
TYPE.with(|t| t.clone())
630+
BUILTIN.with(|types| types.logical_point_type.clone())
615631
}
616632

617633
pub fn font_metrics_type() -> Type {
618-
thread_local! {
619-
static TYPE: Type = Type::Struct(Rc::new(Struct {
620-
fields: IntoIterator::into_iter([
621-
(SmolStr::new_static("ascent"), Type::LogicalLength),
622-
(SmolStr::new_static("descent"), Type::LogicalLength),
623-
(SmolStr::new_static("x-height"), Type::LogicalLength),
624-
(SmolStr::new_static("cap-height"), Type::LogicalLength),
625-
])
626-
.collect(),
627-
name: Some("slint::private_api::FontMetrics".into()),
628-
node: None,
629-
rust_attributes: None,
630-
}));
631-
}
632-
TYPE.with(|t| t.clone())
634+
BUILTIN.with(|types| types.font_metrics_type.clone())
633635
}

0 commit comments

Comments
 (0)