1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 13:00:36 -05:00

perf(core): optimize waker capture in AsyncRefCell (#12332)

This commit is contained in:
Bert Belder 2021-11-02 08:15:20 +01:00
parent 80d3a5f8be
commit 4c468628d4
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461

View file

@ -322,9 +322,8 @@ mod internal {
// is updated, it should be impossible to add it to the current borrow.
assert!(id > turn || borrow_count.try_add(M::borrow_mode()).is_none());
// Save or update the waiter's Waker.
// TODO(piscisaureus): Use will_wake() to make this more efficient.
let waiter_mut = waiters[id - turn].as_mut().unwrap();
waiter_mut.set_waker(cx.waker().clone());
waiter_mut.set_waker(cx.waker());
Poll::Pending
}
}
@ -593,8 +592,15 @@ mod internal {
self.borrow_mode
}
pub fn set_waker(&mut self, waker: Waker) {
self.waker.replace(waker);
pub fn set_waker(&mut self, new_waker: &Waker) {
if self
.waker
.as_ref()
.filter(|waker| waker.will_wake(new_waker))
.is_none()
{
self.waker.replace(new_waker.clone());
}
}
pub fn take_waker(&mut self) -> Option<Waker> {