Skip to content

Commit

Permalink
Use Waker::will_wake() to avoid a cloning op (#2723)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda authored and taiki-e committed Mar 30, 2023
1 parent a730a19 commit 94e020d
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 94e020d

Please sign in to comment.