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
|
|
@ -5,11 +5,11 @@ use iced_core::Padding;
|
|||
use iced_widget::container::Catalog;
|
||||
|
||||
use crate::{
|
||||
theme,
|
||||
Apply, Element, theme,
|
||||
widget::{container, divider, vertical_space},
|
||||
Apply, Element,
|
||||
};
|
||||
|
||||
#[inline]
|
||||
pub fn list_column<'a, Message: 'static>() -> ListColumn<'a, Message> {
|
||||
ListColumn::default()
|
||||
}
|
||||
|
|
@ -42,48 +42,61 @@ impl<Message: 'static> Default for ListColumn<'_, Message> {
|
|||
}
|
||||
|
||||
impl<'a, Message: 'static> ListColumn<'a, Message> {
|
||||
#[inline]
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
#[allow(clippy::should_implement_trait)]
|
||||
pub fn add(mut self, item: impl Into<Element<'a, Message>>) -> Self {
|
||||
if !self.children.is_empty() {
|
||||
self.children.push(
|
||||
container(divider::horizontal::default())
|
||||
.padding([0, self.divider_padding])
|
||||
.into(),
|
||||
);
|
||||
pub fn add(self, item: impl Into<Element<'a, Message>>) -> Self {
|
||||
#[inline(never)]
|
||||
fn inner<'a, Message: 'static>(
|
||||
mut this: ListColumn<'a, Message>,
|
||||
item: Element<'a, Message>,
|
||||
) -> ListColumn<'a, Message> {
|
||||
if !this.children.is_empty() {
|
||||
this.children.push(
|
||||
container(divider::horizontal::default())
|
||||
.padding([0, this.divider_padding])
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
|
||||
// Ensure a minimum height of 32.
|
||||
let list_item = iced::widget::row![
|
||||
container(item).align_y(iced::Alignment::Center),
|
||||
vertical_space().height(iced::Length::Fixed(32.))
|
||||
]
|
||||
.padding(this.list_item_padding)
|
||||
.align_y(iced::Alignment::Center);
|
||||
|
||||
this.children.push(list_item.into());
|
||||
this
|
||||
}
|
||||
|
||||
// Ensure a minimum height of 32.
|
||||
let list_item = iced::widget::row![
|
||||
container(item).align_y(iced::Alignment::Center),
|
||||
vertical_space().height(iced::Length::Fixed(32.))
|
||||
]
|
||||
.padding(self.list_item_padding)
|
||||
.align_y(iced::Alignment::Center);
|
||||
|
||||
self.children.push(list_item.into());
|
||||
self
|
||||
inner(self, item.into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn spacing(mut self, spacing: u16) -> Self {
|
||||
self.spacing = spacing;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the style variant of this [`Circular`].
|
||||
#[inline]
|
||||
pub fn style(mut self, style: <crate::Theme as Catalog>::Class<'a>) -> Self {
|
||||
self.style = style;
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn padding(mut self, padding: impl Into<Padding>) -> Self {
|
||||
self.padding = padding.into();
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn divider_padding(mut self, padding: u16) -> Self {
|
||||
self.divider_padding = padding;
|
||||
self
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue