about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2024-01-11 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2024-01-11 19:39:49 +0100
commit9d84589a96c4f14cb9ac955b8708412854f9246b (patch)
tree8b427f87331db8c7b74b009d904358d9adf67c5c
parent062e7c6a951c1e4f33c0a6f6761755949cde15ec (diff)
downloadrust-9d84589a96c4f14cb9ac955b8708412854f9246b.tar.gz
rust-9d84589a96c4f14cb9ac955b8708412854f9246b.zip
Waker::will_wake: Compare vtable address instead of its content
Optimize will_wake implementation by comparing vtable address instead
of its content.

The existing best practice to avoid false negatives from will_wake is
to define a waker vtable as a static item. That approach continues to
works with the new implementation.

While this potentially changes the observable behaviour, the function is
documented to work on a best-effort basis. The PartialEq impl for
RawWaker remains as it was.
-rw-r--r--library/core/src/task/wake.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs
index 9c41b8b4f46..d6169c4a119 100644
--- a/library/core/src/task/wake.rs
+++ b/library/core/src/task/wake.rs
@@ -313,7 +313,9 @@ impl Waker {
     #[must_use]
     #[stable(feature = "futures_api", since = "1.36.0")]
     pub fn will_wake(&self, other: &Waker) -> bool {
-        self.waker == other.waker
+        let RawWaker { data: a_data, vtable: a_vtable } = self.waker;
+        let RawWaker { data: b_data, vtable: b_vtable } = other.waker;
+        a_data == b_data && ptr::eq(a_vtable, b_vtable)
     }
 
     /// Creates a new `Waker` from [`RawWaker`].