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
|
|
@ -6,16 +6,16 @@ use std::collections::HashMap;
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::{Action, Application, ApplicationExt, Subscription};
|
||||
use crate::theme::{Theme, ThemeType, THEME};
|
||||
use crate::{keyboard_nav, Core, Element};
|
||||
use crate::theme::{THEME, Theme, ThemeType};
|
||||
use crate::{Core, Element, keyboard_nav};
|
||||
#[cfg(feature = "wayland")]
|
||||
use cctk::sctk::reexports::csd_frame::{WindowManagerCapabilities, WindowState};
|
||||
use cosmic_theme::ThemeMode;
|
||||
#[cfg(feature = "wayland")]
|
||||
use iced::event::wayland;
|
||||
#[cfg(not(any(feature = "multi-window", feature = "wayland")))]
|
||||
use iced::Application as IcedApplication;
|
||||
use iced::{window, Task};
|
||||
#[cfg(feature = "wayland")]
|
||||
use iced::event::wayland;
|
||||
use iced::{Task, window};
|
||||
use iced_futures::event::listen_with;
|
||||
use palette::color_difference::EuclideanDistance;
|
||||
|
||||
|
|
@ -243,6 +243,7 @@ where
|
|||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
#[cold]
|
||||
pub fn subscription(&self) -> Subscription<crate::Action<T::Message>> {
|
||||
let window_events = listen_with(|event, _, id| {
|
||||
match event {
|
||||
|
|
@ -410,6 +411,7 @@ where
|
|||
|
||||
impl<T: Application> Cosmic<T> {
|
||||
#[allow(clippy::unused_self)]
|
||||
#[cold]
|
||||
pub fn close(&mut self) -> iced::Task<crate::Action<T::Message>> {
|
||||
if let Some(id) = self.app.core().main_window_id() {
|
||||
iced::window::close(id)
|
||||
|
|
@ -490,10 +492,10 @@ impl<T: Application> Cosmic<T> {
|
|||
|
||||
Action::KeyboardNav(message) => match message {
|
||||
keyboard_nav::Action::FocusNext => {
|
||||
return iced::widget::focus_next().map(crate::Action::Cosmic)
|
||||
return iced::widget::focus_next().map(crate::Action::Cosmic);
|
||||
}
|
||||
keyboard_nav::Action::FocusPrevious => {
|
||||
return iced::widget::focus_previous().map(crate::Action::Cosmic)
|
||||
return iced::widget::focus_previous().map(crate::Action::Cosmic);
|
||||
}
|
||||
keyboard_nav::Action::Escape => return self.app.on_escape(),
|
||||
keyboard_nav::Action::Search => return self.app.on_search(),
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ pub mod settings;
|
|||
|
||||
pub type Task<M> = iced::Task<crate::Action<M>>;
|
||||
|
||||
pub use crate::Core;
|
||||
use crate::prelude::*;
|
||||
use crate::theme::THEME;
|
||||
use crate::widget::{container, horizontal_space, id_container, menu, nav_bar, popover};
|
||||
pub use crate::Core;
|
||||
use apply::Apply;
|
||||
use context_drawer::ContextDrawer;
|
||||
use iced::window;
|
||||
|
|
@ -28,6 +28,7 @@ use iced::{Length, Subscription};
|
|||
pub use settings::Settings;
|
||||
use std::borrow::Cow;
|
||||
|
||||
#[cold]
|
||||
pub(crate) fn iced_settings<App: Application>(
|
||||
settings: Settings,
|
||||
flags: App::Flags,
|
||||
|
|
@ -681,11 +682,10 @@ impl<App: Application> ApplicationExt for App {
|
|||
};
|
||||
|
||||
// Ensures visually aligned radii for content and window corners
|
||||
let window_corner_radius =
|
||||
crate::theme::active()
|
||||
.cosmic()
|
||||
.radius_s()
|
||||
.map(|x| if x < 4.0 { x } else { x + 4.0 });
|
||||
let window_corner_radius = crate::theme::active()
|
||||
.cosmic()
|
||||
.radius_s()
|
||||
.map(|x| if x < 4.0 { x } else { x + 4.0 });
|
||||
|
||||
let view_column = crate::widget::column::with_capacity(2)
|
||||
.push_maybe(if core.window.show_headerbar {
|
||||
|
|
@ -811,6 +811,7 @@ const EMBEDDED_FONTS: &[&[u8]] = &[
|
|||
include_bytes!("../../res/noto/NotoSansMono-Bold.ttf"),
|
||||
];
|
||||
|
||||
#[cold]
|
||||
fn preload_fonts() {
|
||||
let mut font_system = iced::advanced::graphics::text::font_system()
|
||||
.write()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue