Skip to content

Commit

Permalink
Waker::will_wake: Compare vtable address instead of its content
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tmiasko committed Jan 11, 2024
1 parent 062e7c6 commit 9d84589
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion library/core/src/task/wake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
Expand Down

0 comments on commit 9d84589

Please sign in to comment.