Skip to content

Commit cc0e342

Browse files
authored
Use Waker::will_wake() to avoid a cloning op (#2723)
1 parent 066f1d0 commit cc0e342

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

futures-core/src/task/__internal/atomic_waker.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,12 @@ impl AtomicWaker {
271271
WAITING => {
272272
unsafe {
273273
// Locked acquired, update the waker cell
274-
*self.waker.get() = Some(waker.clone());
274+
275+
// Avoid cloning the waker if the old waker will awaken the same task.
276+
match &*self.waker.get() {
277+
Some(old_waker) if old_waker.will_wake(waker) => (),
278+
_ => *self.waker.get() = Some(waker.clone()),
279+
}
275280

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

0 commit comments

Comments
 (0)