Skip to content

Commit

Permalink
Auto merge of rust-lang#119863 - tmiasko:will-wake, r=m-ou-se
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Feb 15, 2024
2 parents fa9f77f + 9d84589 commit 62fb0db
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 @@ -441,7 +441,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 62fb0db

Please sign in to comment.