From 5e72d8db8464fbf6f17b304d9a3c3540ab6e160d Mon Sep 17 00:00:00 2001 From: Christian Meissl Date: Sun, 5 May 2024 10:40:36 +0200 Subject: [PATCH] wayland-server: inline a few more common functions these have shown up in a lot of traces in smithay --- wayland-backend/src/server_api.rs | 2 ++ wayland-scanner/src/server_gen.rs | 4 ++++ wayland-server/src/lib.rs | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/wayland-backend/src/server_api.rs b/wayland-backend/src/server_api.rs index 6e3565db1c0..b3314870bd3 100644 --- a/wayland-backend/src/server_api.rs +++ b/wayland-backend/src/server_api.rs @@ -249,6 +249,7 @@ impl WeakHandle { /// Try to upgrade this weak handle to a [`Handle`] /// /// Returns `None` if the associated backend was already dropped. + #[inline] pub fn upgrade(&self) -> Option { self.handle.upgrade().map(|handle| Handle { handle }) } @@ -256,6 +257,7 @@ impl WeakHandle { impl Handle { /// Get a [`WeakHandle`] from this handle + #[inline] pub fn downgrade(&self) -> WeakHandle { WeakHandle { handle: self.handle.downgrade() } } diff --git a/wayland-scanner/src/server_gen.rs b/wayland-scanner/src/server_gen.rs index 8f4a27f4d12..af13af35e52 100644 --- a/wayland-scanner/src/server_gen.rs +++ b/wayland-scanner/src/server_gen.rs @@ -83,6 +83,7 @@ fn generate_objects_for(interface: &Interface) -> TokenStream { } impl std::cmp::PartialEq for #iface_name { + #[inline] fn eq(&self, other: &#iface_name) -> bool { self.id == other.id } @@ -91,18 +92,21 @@ fn generate_objects_for(interface: &Interface) -> TokenStream { impl std::cmp::Eq for #iface_name {} impl PartialEq> for #iface_name { + #[inline] fn eq(&self, other: &Weak<#iface_name>) -> bool { self.id == other.id() } } impl std::borrow::Borrow for #iface_name { + #[inline] fn borrow(&self) -> &ObjectId { &self.id } } impl std::hash::Hash for #iface_name { + #[inline] fn hash(&self, state: &mut H) { self.id.hash(state) } diff --git a/wayland-server/src/lib.rs b/wayland-server/src/lib.rs index 32edd119bb9..74f8744a58a 100644 --- a/wayland-server/src/lib.rs +++ b/wayland-server/src/lib.rs @@ -160,6 +160,7 @@ pub trait Resource: Clone + std::fmt::Debug + Sized { fn version(&self) -> u32; /// Checks if the Wayland object associated with this proxy is still alive + #[inline] fn is_alive(&self) -> bool { if let Some(handle) = self.handle().upgrade() { handle.object_info(self.id()).is_ok() @@ -231,6 +232,7 @@ pub trait Resource: Clone + std::fmt::Debug + Sized { /// /// This can be of use if you need to store resources in the used data of other objects and want /// to be sure to avoid reference cycles that would cause memory leaks. + #[inline] fn downgrade(&self) -> Weak { Weak { handle: self.handle().clone(), id: self.id(), _iface: std::marker::PhantomData } } @@ -285,6 +287,7 @@ impl Weak { /// This will fail if either: /// - the object represented by this handle has already been destroyed at the protocol level /// - the Wayland connection has already been closed + #[inline] pub fn upgrade(&self) -> Result { let handle = self.handle.upgrade().ok_or(InvalidId)?; // Check if the object has been destroyed @@ -313,6 +316,7 @@ impl Weak { } impl PartialEq for Weak { + #[inline] fn eq(&self, other: &Self) -> bool { self.id == other.id } @@ -321,12 +325,14 @@ impl PartialEq for Weak { impl Eq for Weak {} impl Hash for Weak { + #[inline] fn hash(&self, state: &mut H) { self.id.hash(state); } } impl PartialEq for Weak { + #[inline] fn eq(&self, other: &I) -> bool { self.id == other.id() }