Skip to content

Commit

Permalink
Use Waker::will_wake() to avoid a cloning op
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Mar 18, 2023
1 parent 8253b78 commit cbd393f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion futures-core/src/task/__internal/atomic_waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,12 @@ impl AtomicWaker {
WAITING => {
unsafe {
// Locked acquired, update the waker cell
*self.waker.get() = Some(waker.clone());

// Avoid cloning the waker if the old waker will awaken the same task.
match &*self.waker.get() {
Some(old_waker) if old_waker.will_wake(waker) => (),
_ => *self.waker.get() = Some(waker.clone()),
}

// Release the lock. If the state transitioned to include
// the `WAKING` bit, this means that at least one wake has
Expand Down

0 comments on commit cbd393f

Please sign in to comment.