about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2024-08-09 18:05:57 +0200
committerRalf Jung <post@ralfj.de>2024-08-09 18:05:57 +0200
commitae09340350fd8b7aa7a00a81132a7e77772504cb (patch)
tree5f7b656a59db3e36ec13167106914f06c5eaace7
parent899eb03926be23f2e5d2ffcaa1d6f9ac40af7f13 (diff)
downloadrust-ae09340350fd8b7aa7a00a81132a7e77772504cb.tar.gz
rust-ae09340350fd8b7aa7a00a81132a7e77772504cb.zip
make LocalWaker::will_wake consistent with Waker::will_wake
-rw-r--r--library/core/src/task/wake.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs
index 8ce3eb2ea39..29932c0d1ff 100644
--- a/library/core/src/task/wake.rs
+++ b/library/core/src/task/wake.rs
@@ -502,6 +502,8 @@ impl Waker {
     #[must_use]
     #[stable(feature = "futures_api", since = "1.36.0")]
     pub fn will_wake(&self, other: &Waker) -> bool {
+        // We optimize this by comparing vtable addresses instead of vtable contents.
+        // This is permitted since the function is documented as best-effort.
         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)
@@ -761,7 +763,11 @@ impl LocalWaker {
     #[must_use]
     #[unstable(feature = "local_waker", issue = "118959")]
     pub fn will_wake(&self, other: &LocalWaker) -> bool {
-        self.waker == other.waker
+        // We optimize this by comparing vtable addresses instead of vtable contents.
+        // This is permitted since the function is documented as best-effort.
+        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 `LocalWaker` from [`RawWaker`].