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:
Michael Aaron Murphy 2025-03-21 03:17:59 +01:00
parent c538d672df
commit 8cf372c9b9
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
55 changed files with 702 additions and 255 deletions

View file

@ -6,7 +6,7 @@
use std::cmp;
use crate::iced_core::{Alignment, Length, Padding};
use crate::widget::{button, column, grid, icon, row, text, Grid};
use crate::widget::{Grid, button, column, grid, icon, row, text};
use chrono::{Datelike, Days, Local, Months, NaiveDate, Weekday};
/// A widget that displays an interactive calendar.
@ -58,6 +58,7 @@ impl CalendarModel {
}
}
#[inline]
pub fn new(selected: NaiveDate, visible: NaiveDate) -> Self {
CalendarModel { selected, visible }
}
@ -80,16 +81,19 @@ impl CalendarModel {
self.visible = next_month_date;
}
#[inline]
pub fn set_prev_month(&mut self) {
self.show_prev_month();
self.selected = self.visible;
}
#[inline]
pub fn set_next_month(&mut self) {
self.show_next_month();
self.selected = self.visible;
}
#[inline]
pub fn set_selected_visible(&mut self, selected: NaiveDate) {
self.selected = selected;
self.visible = self.selected;
@ -225,6 +229,7 @@ fn padded_control<'a, Message>(
.width(Length::Fill)
}
#[inline]
fn menu_control_padding() -> Padding {
let guard = crate::theme::THEME.lock().unwrap();
let cosmic = guard.cosmic();