diff --git a/hammond-gtk/src/app.rs b/hammond-gtk/src/app.rs index f25ae78..81e12de 100644 --- a/hammond-gtk/src/app.rs +++ b/hammond-gtk/src/app.rs @@ -147,6 +147,7 @@ impl App { }); } + #[inline] pub fn run(self) { WindowGeometry::from_settings(&self.settings).apply(&self.window); diff --git a/hammond-gtk/src/utils.rs b/hammond-gtk/src/utils.rs index 8e0f4b2..568d1df 100644 --- a/hammond-gtk/src/utils.rs +++ b/hammond-gtk/src/utils.rs @@ -211,6 +211,7 @@ lazy_static! { // GObjects do not implement Send trait, so SendCell is a way around that. // Also lazy_static requires Sync trait, so that's what the mutexes are. // TODO: maybe use something that would just scale to requested size? +#[inline] pub fn set_image_from_path( image: >k::Image, pd: Arc, diff --git a/hammond-gtk/src/views/empty.rs b/hammond-gtk/src/views/empty.rs index ad3d152..40ffa16 100644 --- a/hammond-gtk/src/views/empty.rs +++ b/hammond-gtk/src/views/empty.rs @@ -6,6 +6,7 @@ pub struct EmptyView { } impl Default for EmptyView { + #[inline] fn default() -> Self { let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/empty_view.ui"); let view: gtk::Box = builder.get_object("empty_view").unwrap(); @@ -15,6 +16,7 @@ impl Default for EmptyView { } impl EmptyView { + #[inline] pub fn new() -> EmptyView { EmptyView::default() } diff --git a/hammond-gtk/src/views/episodes.rs b/hammond-gtk/src/views/episodes.rs index bcdcd46..1b44f76 100644 --- a/hammond-gtk/src/views/episodes.rs +++ b/hammond-gtk/src/views/episodes.rs @@ -40,6 +40,7 @@ pub struct EpisodesView { } impl Default for EpisodesView { + #[inline] fn default() -> Self { let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episodes_view.ui"); let container: gtk::Box = builder.get_object("container").unwrap(); @@ -76,6 +77,7 @@ impl Default for EpisodesView { // TODO: REFACTOR ME impl EpisodesView { + #[inline] pub fn new(sender: Sender) -> Result { let view = EpisodesView::default(); let ignore = get_ignored_shows()?; @@ -130,6 +132,7 @@ impl EpisodesView { Ok(view) } + #[inline] pub fn is_empty(&self) -> bool { if !self.today_list.get_children().is_empty() { return false; @@ -154,12 +157,14 @@ impl EpisodesView { true } + #[inline] /// Set scrolled window vertical adjustment. pub fn set_vadjustment(&self, vadjustment: >k::Adjustment) { self.scrolled_window.set_vadjustment(vadjustment) } } +#[inline] fn split(now: &DateTime, epoch: i64) -> ListSplit { let ep = Utc.timestamp(epoch, 0); @@ -184,6 +189,7 @@ struct EpisodesViewWidget { } impl Default for EpisodesViewWidget { + #[inline] fn default() -> Self { let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episodes_view_widget.ui"); @@ -219,6 +225,7 @@ impl EpisodesViewWidget { view } + #[inline] fn init(&self, podcast_id: i32) { self.set_cover(podcast_id) .map_err(|err| error!("Failed to set a cover: {}", err)) @@ -227,6 +234,7 @@ impl EpisodesViewWidget { self.container.pack_start(&self.episode, true, true, 6); } + #[inline] fn set_cover(&self, podcast_id: i32) -> Result<(), Error> { let pd = Arc::new(dbqueries::get_podcast_cover_from_id(podcast_id)?); set_image_from_path(&self.image, pd, 64) diff --git a/hammond-gtk/src/views/shows.rs b/hammond-gtk/src/views/shows.rs index d17e21c..68dda23 100644 --- a/hammond-gtk/src/views/shows.rs +++ b/hammond-gtk/src/views/shows.rs @@ -19,6 +19,7 @@ pub struct ShowsPopulated { } impl Default for ShowsPopulated { + #[inline] fn default() -> Self { let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/shows_view.ui"); let container: gtk::Box = builder.get_object("fb_parent").unwrap(); @@ -34,12 +35,14 @@ impl Default for ShowsPopulated { } impl ShowsPopulated { + #[inline] pub fn new(sender: Sender) -> Result { let pop = ShowsPopulated::default(); pop.init(sender)?; Ok(pop) } + #[inline] pub fn init(&self, sender: Sender) -> Result<(), Error> { self.flowbox.connect_child_activated(move |_, child| { on_child_activate(child, sender.clone()) @@ -50,6 +53,7 @@ impl ShowsPopulated { self.populate_flowbox() } + #[inline] fn populate_flowbox(&self) -> Result<(), Error> { let ignore = get_ignored_shows()?; let podcasts = dbqueries::get_podcasts_filter(&ignore)?; @@ -62,16 +66,19 @@ impl ShowsPopulated { Ok(()) } + #[inline] pub fn is_empty(&self) -> bool { self.flowbox.get_children().is_empty() } + #[inline] /// Set scrolled window vertical adjustment. pub fn set_vadjustment(&self, vadjustment: >k::Adjustment) { self.scrolled_window.set_vadjustment(vadjustment) } } +#[inline] fn on_child_activate(child: >k::FlowBoxChild, sender: Sender) -> Result<(), Error> { use gtk::WidgetExt; @@ -95,6 +102,7 @@ struct ShowsChild { } impl Default for ShowsChild { + #[inline] fn default() -> Self { let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/shows_child.ui"); @@ -113,12 +121,14 @@ impl Default for ShowsChild { } impl ShowsChild { + #[inline] pub fn new(pd: Podcast) -> ShowsChild { let child = ShowsChild::default(); child.init(pd); child } + #[inline] fn init(&self, pd: Podcast) { self.container.set_tooltip_text(pd.title()); WidgetExt::set_name(&self.child, &pd.id().to_string()); @@ -128,6 +138,7 @@ impl ShowsChild { .ok(); } + #[inline] fn set_cover(&self, pd: Arc) -> Result<(), Error> { set_image_from_path(&self.cover, pd, 256) } diff --git a/hammond-gtk/src/widgets/episode.rs b/hammond-gtk/src/widgets/episode.rs index fa43c11..988caff 100644 --- a/hammond-gtk/src/widgets/episode.rs +++ b/hammond-gtk/src/widgets/episode.rs @@ -32,6 +32,7 @@ pub struct EpisodeWidget { } impl Default for EpisodeWidget { + #[inline] fn default() -> Self { let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episode_widget.ui"); @@ -78,12 +79,14 @@ impl Default for EpisodeWidget { } impl EpisodeWidget { + #[inline] pub fn new(episode: EpisodeWidgetQuery, sender: Sender) -> EpisodeWidget { let mut widget = EpisodeWidget::default(); widget.init(episode, sender); widget } + #[inline] fn init(&mut self, episode: EpisodeWidgetQuery, sender: Sender) { // Set the date label. self.set_date(episode.epoch()); @@ -104,6 +107,7 @@ impl EpisodeWidget { self.connect_buttons(episode, sender); } + #[inline] fn connect_buttons(&self, episode: Arc>, sender: Sender) { let title = self.title.clone(); if let Ok(media) = self.media.lock() { @@ -136,6 +140,7 @@ impl EpisodeWidget { } } + #[inline] /// Determine the title state. fn set_title(&mut self, episode: &EpisodeWidgetQuery) { let mut machine = self.title.borrow_mut(); @@ -145,12 +150,14 @@ impl EpisodeWidget { }); } + #[inline] /// Set the date label depending on the current time. fn set_date(&mut self, epoch: i32) { let machine = &mut self.date; take_mut::take(machine, |date| date.determine_state(i64::from(epoch))); } + #[inline] /// Set the duration label. fn set_duration(&mut self, seconds: Option) { let machine = &mut self.duration; @@ -158,6 +165,7 @@ impl EpisodeWidget { } } +#[inline] fn determine_media_state( media_machine: Arc>, episode: &EpisodeWidgetQuery, @@ -244,6 +252,7 @@ fn on_play_bttn_clicked( Ok(()) } +#[inline] fn open_uri(rowid: i32) -> Result<(), Error> { let uri = dbqueries::get_episode_local_uri_from_id(rowid)? .ok_or_else(|| format_err!("Expected Some found None."))?; diff --git a/hammond-gtk/src/widgets/episode_states.rs b/hammond-gtk/src/widgets/episode_states.rs index e93f90c..250bc7c 100644 --- a/hammond-gtk/src/widgets/episode_states.rs +++ b/hammond-gtk/src/widgets/episode_states.rs @@ -61,6 +61,7 @@ pub struct Title { impl Title { #[allow(unused_must_use)] + #[inline] // This does not need to be &mut since gtk-rs does not model ownership // But I think it wouldn't hurt if we treat it as a Rust api. fn set_title(&mut self, s: &str) { @@ -69,6 +70,7 @@ impl Title { } impl Title { + #[inline] fn new(title: gtk::Label) -> Self { Title { title, @@ -78,6 +80,7 @@ impl Title { } impl From> for Title { + #[inline] fn from(f: Title) -> Self { f.title .get_style_context() @@ -91,6 +94,7 @@ impl From> for Title { } impl From> for Title { + #[inline] fn from(f: Title) -> Self { f.title .get_style_context() @@ -110,11 +114,13 @@ pub enum TitleMachine { } impl TitleMachine { + #[inline] pub fn new(label: gtk::Label, is_played: bool) -> Self { let m = TitleMachine::Normal(Title::::new(label)); m.determine_state(is_played) } + #[inline] pub fn determine_state(self, is_played: bool) -> Self { use self::TitleMachine::*; @@ -126,6 +132,7 @@ impl TitleMachine { } } + #[inline] pub fn set_title(&mut self, s: &str) { use self::TitleMachine::*; @@ -149,6 +156,7 @@ pub struct Date { } impl Date { + #[inline] fn into_usual(self, epoch: i64) -> Date { let ts = Utc.timestamp(epoch, 0); self.date.set_text(ts.format("%e %b").to_string().trim()); @@ -160,6 +168,7 @@ impl Date { } } + #[inline] fn into_year_shown(self, epoch: i64) -> Date { let ts = Utc.timestamp(epoch, 0); self.date.set_text(ts.format("%e %b %Y").to_string().trim()); @@ -173,6 +182,7 @@ impl Date { } impl Date { + #[inline] fn new(date: gtk::Label, epoch: i64) -> Self { let ts = Utc.timestamp(epoch, 0); date.set_text(ts.format("%e %b %Y").to_string().trim()); @@ -193,11 +203,13 @@ pub enum DateMachine { } impl DateMachine { + #[inline] pub fn new(label: gtk::Label, epoch: i64) -> Self { let m = DateMachine::UnInitialized(Date::::new(label, epoch)); m.determine_state(epoch) } + #[inline] pub fn determine_state(self, epoch: i64) -> Self { use self::DateMachine::*; @@ -227,6 +239,7 @@ pub struct Duration { } impl Duration { + #[inline] // This needs a better name. // TODO: make me mut fn set_duration(&self, minutes: i64) { @@ -235,6 +248,7 @@ impl Duration { } impl Duration { + #[inline] fn new(duration: gtk::Label, separator: gtk::Label) -> Self { duration.hide(); separator.hide(); @@ -248,6 +262,7 @@ impl Duration { } impl From> for Duration { + #[inline] fn from(f: Duration) -> Self { f.duration.show(); f.separator.show(); @@ -261,6 +276,7 @@ impl From> for Duration { } impl From> for Duration { + #[inline] fn from(f: Duration) -> Self { f.duration.hide(); f.separator.hide(); @@ -280,11 +296,13 @@ pub enum DurationMachine { } impl DurationMachine { + #[inline] pub fn new(duration: gtk::Label, separator: gtk::Label, seconds: Option) -> Self { let m = DurationMachine::Hidden(Duration::::new(duration, separator)); m.determine_state(seconds) } + #[inline] pub fn determine_state(self, seconds: Option) -> Self { match (self, seconds) { (d @ DurationMachine::Hidden(_), None) => d, @@ -319,6 +337,7 @@ pub struct Size { } impl Size { + #[inline] fn set_size(self, s: &str) -> Size { self.size.set_text(s); self.size.show(); @@ -330,6 +349,7 @@ impl Size { } } + #[inline] // https://play.rust-lang.org/?gist=1acffaf62743eeb85be1ae6ecf474784&version=stable // It might be possible to make a generic definition with Specialization. // https://github.com/rust-lang/rust/issues/31844 @@ -344,6 +364,7 @@ impl Size { } } + #[inline] fn into_hidden(self) -> Size { self.size.hide(); self.separator.hide(); @@ -357,6 +378,7 @@ impl Size { } impl Size { + #[inline] fn new(size: gtk::Label, separator: gtk::Label) -> Self { size.hide(); separator.hide(); @@ -390,6 +412,7 @@ pub struct DownloadPlay { } impl DownloadPlay { + #[inline] // https://play.rust-lang.org/?gist=1acffaf62743eeb85be1ae6ecf474784&version=stable // It might be possible to make a generic definition with Specialization. // https://github.com/rust-lang/rust/issues/31844 @@ -404,6 +427,7 @@ impl DownloadPlay { } } + #[inline] fn into_fetchable(self) -> DownloadPlay { self.play.hide(); self.download.show(); @@ -415,6 +439,7 @@ impl DownloadPlay { } } + #[inline] fn into_hidden(self) -> DownloadPlay { self.play.hide(); self.download.hide(); @@ -426,6 +451,7 @@ impl DownloadPlay { } } + #[inline] fn download_connect_clicked( &self, f: F, @@ -433,12 +459,14 @@ impl DownloadPlay { self.download.connect_clicked(f) } + #[inline] fn play_connect_clicked(&self, f: F) -> glib::SignalHandlerId { self.play.connect_clicked(f) } } impl DownloadPlay { + #[inline] fn new(play: gtk::Button, download: gtk::Button) -> Self { play.hide(); download.hide(); @@ -461,6 +489,7 @@ pub struct Progress { } impl Progress { + #[inline] fn into_shown(self) -> Progress { self.bar.show(); self.cancel.show(); @@ -476,6 +505,7 @@ impl Progress { } } + #[inline] fn into_hidden(self) -> Progress { self.bar.hide(); self.cancel.hide(); @@ -492,6 +522,7 @@ impl Progress { } #[allow(unused_must_use)] + #[inline] // This does not need to be &mut since gtk-rs does not model ownership // But I think it wouldn't hurt if we treat it as a Rust api. fn update_progress(&mut self, local_size: &str, fraction: f64) { @@ -499,12 +530,14 @@ impl Progress { self.bar.set_fraction(fraction); } + #[inline] fn cancel_connect_clicked(&self, f: F) -> glib::SignalHandlerId { self.cancel.connect_clicked(f) } } impl Progress { + #[inline] fn new( bar: gtk::ProgressBar, cancel: gtk::Button, @@ -538,6 +571,7 @@ type Playable = Media