perf: inline public getters/setters, and use non-generic inner functions
To reduce compile-times and avoid some overhead to binary size, this will modify some of our generic functions to use non-generic inner functions where possible. The inner functions are marked carefully with `#[inline(never)]` to prevent being inlined by LLVM at their callsites While looking for generic functions to optimize, I have also taken the opportunity to annotate public non-generic getters and setters with `#[inline]` to ensure that LLVM will inline them across crate boundaries. By default, only generic functions are automatically inlined, and only when enabling fat LTO are constant functions reliably inlined across crate boundaries.
This commit is contained in:
parent
c538d672df
commit
8cf372c9b9
55 changed files with 702 additions and 255 deletions
|
|
@ -26,72 +26,117 @@ pub enum Typography {
|
|||
|
||||
/// [`Text`] widget with the Title 1 typography preset.
|
||||
pub fn title1<'a>(text: impl Into<Cow<'a, str>> + 'a) -> Text<'a, crate::Theme, Renderer> {
|
||||
Text::new(text.into())
|
||||
.size(35.0)
|
||||
.line_height(LineHeight::Absolute(52.0.into()))
|
||||
.font(crate::font::semibold())
|
||||
#[inline(never)]
|
||||
fn inner(text: Cow<str>) -> Text<crate::Theme, Renderer> {
|
||||
Text::new(text)
|
||||
.size(35.0)
|
||||
.line_height(LineHeight::Absolute(52.0.into()))
|
||||
.font(crate::font::semibold())
|
||||
}
|
||||
|
||||
inner(text.into())
|
||||
}
|
||||
|
||||
/// [`Text`] widget with the Title 2 typography preset.
|
||||
pub fn title2<'a>(text: impl Into<Cow<'a, str>> + 'a) -> Text<'a, crate::Theme, Renderer> {
|
||||
Text::new(text.into())
|
||||
.size(29.0)
|
||||
.line_height(LineHeight::Absolute(43.0.into()))
|
||||
.font(crate::font::semibold())
|
||||
#[inline(never)]
|
||||
fn inner(text: Cow<str>) -> Text<crate::Theme, Renderer> {
|
||||
Text::new(text)
|
||||
.size(29.0)
|
||||
.line_height(LineHeight::Absolute(43.0.into()))
|
||||
.font(crate::font::semibold())
|
||||
}
|
||||
|
||||
inner(text.into())
|
||||
}
|
||||
|
||||
/// [`Text`] widget with the Title 3 typography preset.
|
||||
pub fn title3<'a>(text: impl Into<Cow<'a, str>> + 'a) -> Text<'a, crate::Theme, Renderer> {
|
||||
Text::new(text.into())
|
||||
.size(24.0)
|
||||
.line_height(LineHeight::Absolute(36.0.into()))
|
||||
.font(crate::font::bold())
|
||||
#[inline(never)]
|
||||
fn inner(text: Cow<str>) -> Text<crate::Theme, Renderer> {
|
||||
Text::new(text)
|
||||
.size(24.0)
|
||||
.line_height(LineHeight::Absolute(36.0.into()))
|
||||
.font(crate::font::bold())
|
||||
}
|
||||
|
||||
inner(text.into())
|
||||
}
|
||||
|
||||
/// [`Text`] widget with the Title 4 typography preset.
|
||||
pub fn title4<'a>(text: impl Into<Cow<'a, str>> + 'a) -> Text<'a, crate::Theme, Renderer> {
|
||||
Text::new(text.into())
|
||||
.size(20.0)
|
||||
.line_height(LineHeight::Absolute(30.0.into()))
|
||||
.font(crate::font::bold())
|
||||
#[inline(never)]
|
||||
fn inner(text: Cow<str>) -> Text<crate::Theme, Renderer> {
|
||||
Text::new(text)
|
||||
.size(20.0)
|
||||
.line_height(LineHeight::Absolute(30.0.into()))
|
||||
.font(crate::font::bold())
|
||||
}
|
||||
|
||||
inner(text.into())
|
||||
}
|
||||
|
||||
/// [`Text`] widget with the Heading typography preset.
|
||||
pub fn heading<'a>(text: impl Into<Cow<'a, str>> + 'a) -> Text<'a, crate::Theme, Renderer> {
|
||||
Text::new(text.into())
|
||||
.size(14.0)
|
||||
.line_height(LineHeight::Absolute(iced::Pixels(21.0)))
|
||||
.font(crate::font::bold())
|
||||
#[inline(never)]
|
||||
fn inner(text: Cow<str>) -> Text<crate::Theme, Renderer> {
|
||||
Text::new(text)
|
||||
.size(14.0)
|
||||
.line_height(LineHeight::Absolute(iced::Pixels(21.0)))
|
||||
.font(crate::font::bold())
|
||||
}
|
||||
|
||||
inner(text.into())
|
||||
}
|
||||
|
||||
/// [`Text`] widget with the Caption Heading typography preset.
|
||||
pub fn caption_heading<'a>(text: impl Into<Cow<'a, str>> + 'a) -> Text<'a, crate::Theme, Renderer> {
|
||||
Text::new(text.into())
|
||||
.size(12.0)
|
||||
.line_height(LineHeight::Absolute(iced::Pixels(17.0)))
|
||||
.font(crate::font::semibold())
|
||||
#[inline(never)]
|
||||
fn inner(text: Cow<str>) -> Text<crate::Theme, Renderer> {
|
||||
Text::new(text)
|
||||
.size(12.0)
|
||||
.line_height(LineHeight::Absolute(iced::Pixels(17.0)))
|
||||
.font(crate::font::semibold())
|
||||
}
|
||||
|
||||
inner(text.into())
|
||||
}
|
||||
|
||||
/// [`Text`] widget with the Body typography preset.
|
||||
pub fn body<'a>(text: impl Into<Cow<'a, str>> + 'a) -> Text<'a, crate::Theme, Renderer> {
|
||||
Text::new(text.into())
|
||||
.size(14.0)
|
||||
.line_height(LineHeight::Absolute(21.0.into()))
|
||||
.font(crate::font::default())
|
||||
#[inline(never)]
|
||||
fn inner(text: Cow<str>) -> Text<crate::Theme, Renderer> {
|
||||
Text::new(text)
|
||||
.size(14.0)
|
||||
.line_height(LineHeight::Absolute(21.0.into()))
|
||||
.font(crate::font::default())
|
||||
}
|
||||
|
||||
inner(text.into())
|
||||
}
|
||||
|
||||
/// [`Text`] widget with the Caption typography preset.
|
||||
pub fn caption<'a>(text: impl Into<Cow<'a, str>> + 'a) -> Text<'a, crate::Theme, Renderer> {
|
||||
Text::new(text.into())
|
||||
.size(12.0)
|
||||
.line_height(LineHeight::Absolute(17.0.into()))
|
||||
.font(crate::font::default())
|
||||
#[inline(never)]
|
||||
fn inner(text: Cow<str>) -> Text<crate::Theme, Renderer> {
|
||||
Text::new(text)
|
||||
.size(12.0)
|
||||
.line_height(LineHeight::Absolute(17.0.into()))
|
||||
.font(crate::font::default())
|
||||
}
|
||||
|
||||
inner(text.into())
|
||||
}
|
||||
|
||||
/// [`Text`] widget with the Monotext typography preset.
|
||||
pub fn monotext<'a>(text: impl Into<Cow<'a, str>> + 'a) -> Text<'a, crate::Theme, Renderer> {
|
||||
Text::new(text.into())
|
||||
.size(14.0)
|
||||
.line_height(LineHeight::Absolute(20.0.into()))
|
||||
.font(crate::font::mono())
|
||||
#[inline(never)]
|
||||
fn inner(text: Cow<str>) -> Text<crate::Theme, Renderer> {
|
||||
Text::new(text)
|
||||
.size(14.0)
|
||||
.line_height(LineHeight::Absolute(20.0.into()))
|
||||
.font(crate::font::mono())
|
||||
}
|
||||
|
||||
inner(text.into())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue