Skip to content

Commit 9d84589

Browse files
committed
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.
1 parent 062e7c6 commit 9d84589

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

library/core/src/task/wake.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,9 @@ impl Waker {
313313
#[must_use]
314314
#[stable(feature = "futures_api", since = "1.36.0")]
315315
pub fn will_wake(&self, other: &Waker) -> bool {
316-
self.waker == other.waker
316+
let RawWaker { data: a_data, vtable: a_vtable } = self.waker;
317+
let RawWaker { data: b_data, vtable: b_vtable } = other.waker;
318+
a_data == b_data && ptr::eq(a_vtable, b_vtable)
317319
}
318320

319321
/// Creates a new `Waker` from [`RawWaker`].

0 commit comments

Comments
 (0)