Use `Waker::will_wake()` to avoid a cloning op (#12)

This commit is contained in:
daxpedda 2023-03-22 16:53:54 +01:00 committed by GitHub
parent b96ee39889
commit 4320c6739e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -285,7 +285,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