Skip to content

Commit c1a6269

Browse files
cmeisslids1024
authored andcommitted
wayland-server: inline a few more common functions
these have shown up in a lot of traces in smithay
1 parent 16a11a5 commit c1a6269

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

wayland-backend/src/server_api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,15 @@ impl WeakHandle {
249249
/// Try to upgrade this weak handle to a [`Handle`]
250250
///
251251
/// Returns `None` if the associated backend was already dropped.
252+
#[inline]
252253
pub fn upgrade(&self) -> Option<Handle> {
253254
self.handle.upgrade().map(|handle| Handle { handle })
254255
}
255256
}
256257

257258
impl Handle {
258259
/// Get a [`WeakHandle`] from this handle
260+
#[inline]
259261
pub fn downgrade(&self) -> WeakHandle {
260262
WeakHandle { handle: self.handle.downgrade() }
261263
}

wayland-scanner/src/server_gen.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ fn generate_objects_for(interface: &Interface) -> TokenStream {
8383
}
8484

8585
impl std::cmp::PartialEq for #iface_name {
86+
#[inline]
8687
fn eq(&self, other: &#iface_name) -> bool {
8788
self.id == other.id
8889
}
@@ -91,18 +92,21 @@ fn generate_objects_for(interface: &Interface) -> TokenStream {
9192
impl std::cmp::Eq for #iface_name {}
9293

9394
impl PartialEq<Weak<#iface_name>> for #iface_name {
95+
#[inline]
9496
fn eq(&self, other: &Weak<#iface_name>) -> bool {
9597
self.id == other.id()
9698
}
9799
}
98100

99101
impl std::borrow::Borrow<ObjectId> for #iface_name {
102+
#[inline]
100103
fn borrow(&self) -> &ObjectId {
101104
&self.id
102105
}
103106
}
104107

105108
impl std::hash::Hash for #iface_name {
109+
#[inline]
106110
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
107111
self.id.hash(state)
108112
}

wayland-scanner/tests/scanner_assets/test-server-code.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,26 @@ pub mod wl_callback {
5454
handle: WeakHandle,
5555
}
5656
impl std::cmp::PartialEq for WlCallback {
57+
#[inline]
5758
fn eq(&self, other: &WlCallback) -> bool {
5859
self.id == other.id
5960
}
6061
}
6162
impl std::cmp::Eq for WlCallback {}
6263
impl PartialEq<Weak<WlCallback>> for WlCallback {
64+
#[inline]
6365
fn eq(&self, other: &Weak<WlCallback>) -> bool {
6466
self.id == other.id()
6567
}
6668
}
6769
impl std::borrow::Borrow<ObjectId> for WlCallback {
70+
#[inline]
6871
fn borrow(&self) -> &ObjectId {
6972
&self.id
7073
}
7174
}
7275
impl std::hash::Hash for WlCallback {
76+
#[inline]
7377
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
7478
self.id.hash(state)
7579
}
@@ -316,22 +320,26 @@ pub mod test_global {
316320
handle: WeakHandle,
317321
}
318322
impl std::cmp::PartialEq for TestGlobal {
323+
#[inline]
319324
fn eq(&self, other: &TestGlobal) -> bool {
320325
self.id == other.id
321326
}
322327
}
323328
impl std::cmp::Eq for TestGlobal {}
324329
impl PartialEq<Weak<TestGlobal>> for TestGlobal {
330+
#[inline]
325331
fn eq(&self, other: &Weak<TestGlobal>) -> bool {
326332
self.id == other.id()
327333
}
328334
}
329335
impl std::borrow::Borrow<ObjectId> for TestGlobal {
336+
#[inline]
330337
fn borrow(&self) -> &ObjectId {
331338
&self.id
332339
}
333340
}
334341
impl std::hash::Hash for TestGlobal {
342+
#[inline]
335343
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
336344
self.id.hash(state)
337345
}
@@ -822,22 +830,26 @@ pub mod secondary {
822830
handle: WeakHandle,
823831
}
824832
impl std::cmp::PartialEq for Secondary {
833+
#[inline]
825834
fn eq(&self, other: &Secondary) -> bool {
826835
self.id == other.id
827836
}
828837
}
829838
impl std::cmp::Eq for Secondary {}
830839
impl PartialEq<Weak<Secondary>> for Secondary {
840+
#[inline]
831841
fn eq(&self, other: &Weak<Secondary>) -> bool {
832842
self.id == other.id()
833843
}
834844
}
835845
impl std::borrow::Borrow<ObjectId> for Secondary {
846+
#[inline]
836847
fn borrow(&self) -> &ObjectId {
837848
&self.id
838849
}
839850
}
840851
impl std::hash::Hash for Secondary {
852+
#[inline]
841853
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
842854
self.id.hash(state)
843855
}
@@ -981,22 +993,26 @@ pub mod tertiary {
981993
handle: WeakHandle,
982994
}
983995
impl std::cmp::PartialEq for Tertiary {
996+
#[inline]
984997
fn eq(&self, other: &Tertiary) -> bool {
985998
self.id == other.id
986999
}
9871000
}
9881001
impl std::cmp::Eq for Tertiary {}
9891002
impl PartialEq<Weak<Tertiary>> for Tertiary {
1003+
#[inline]
9901004
fn eq(&self, other: &Weak<Tertiary>) -> bool {
9911005
self.id == other.id()
9921006
}
9931007
}
9941008
impl std::borrow::Borrow<ObjectId> for Tertiary {
1009+
#[inline]
9951010
fn borrow(&self) -> &ObjectId {
9961011
&self.id
9971012
}
9981013
}
9991014
impl std::hash::Hash for Tertiary {
1015+
#[inline]
10001016
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
10011017
self.id.hash(state)
10021018
}
@@ -1140,22 +1156,26 @@ pub mod quad {
11401156
handle: WeakHandle,
11411157
}
11421158
impl std::cmp::PartialEq for Quad {
1159+
#[inline]
11431160
fn eq(&self, other: &Quad) -> bool {
11441161
self.id == other.id
11451162
}
11461163
}
11471164
impl std::cmp::Eq for Quad {}
11481165
impl PartialEq<Weak<Quad>> for Quad {
1166+
#[inline]
11491167
fn eq(&self, other: &Weak<Quad>) -> bool {
11501168
self.id == other.id()
11511169
}
11521170
}
11531171
impl std::borrow::Borrow<ObjectId> for Quad {
1172+
#[inline]
11541173
fn borrow(&self) -> &ObjectId {
11551174
&self.id
11561175
}
11571176
}
11581177
impl std::hash::Hash for Quad {
1178+
#[inline]
11591179
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
11601180
self.id.hash(state)
11611181
}

wayland-server/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ pub trait Resource: Clone + std::fmt::Debug + Sized {
160160
fn version(&self) -> u32;
161161

162162
/// Checks if the Wayland object associated with this proxy is still alive
163+
#[inline]
163164
fn is_alive(&self) -> bool {
164165
if let Some(handle) = self.handle().upgrade() {
165166
handle.object_info(self.id()).is_ok()
@@ -231,6 +232,7 @@ pub trait Resource: Clone + std::fmt::Debug + Sized {
231232
///
232233
/// This can be of use if you need to store resources in the used data of other objects and want
233234
/// to be sure to avoid reference cycles that would cause memory leaks.
235+
#[inline]
234236
fn downgrade(&self) -> Weak<Self> {
235237
Weak { handle: self.handle().clone(), id: self.id(), _iface: std::marker::PhantomData }
236238
}
@@ -285,6 +287,7 @@ impl<I: Resource> Weak<I> {
285287
/// This will fail if either:
286288
/// - the object represented by this handle has already been destroyed at the protocol level
287289
/// - the Wayland connection has already been closed
290+
#[inline]
288291
pub fn upgrade(&self) -> Result<I, InvalidId> {
289292
let handle = self.handle.upgrade().ok_or(InvalidId)?;
290293
// Check if the object has been destroyed
@@ -313,6 +316,7 @@ impl<I: Resource> Weak<I> {
313316
}
314317

315318
impl<I> PartialEq for Weak<I> {
319+
#[inline]
316320
fn eq(&self, other: &Self) -> bool {
317321
self.id == other.id
318322
}
@@ -321,12 +325,14 @@ impl<I> PartialEq for Weak<I> {
321325
impl<I> Eq for Weak<I> {}
322326

323327
impl<I> Hash for Weak<I> {
328+
#[inline]
324329
fn hash<H: Hasher>(&self, state: &mut H) {
325330
self.id.hash(state);
326331
}
327332
}
328333

329334
impl<I: Resource> PartialEq<I> for Weak<I> {
335+
#[inline]
330336
fn eq(&self, other: &I) -> bool {
331337
self.id == other.id()
332338
}

0 commit comments

Comments
 (0)