Skip to content

Commit ae09340

Browse files
committed
make LocalWaker::will_wake consistent with Waker::will_wake
1 parent 899eb03 commit ae09340

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

library/core/src/task/wake.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,8 @@ impl Waker {
502502
#[must_use]
503503
#[stable(feature = "futures_api", since = "1.36.0")]
504504
pub fn will_wake(&self, other: &Waker) -> bool {
505+
// We optimize this by comparing vtable addresses instead of vtable contents.
506+
// This is permitted since the function is documented as best-effort.
505507
let RawWaker { data: a_data, vtable: a_vtable } = self.waker;
506508
let RawWaker { data: b_data, vtable: b_vtable } = other.waker;
507509
a_data == b_data && ptr::eq(a_vtable, b_vtable)
@@ -761,7 +763,11 @@ impl LocalWaker {
761763
#[must_use]
762764
#[unstable(feature = "local_waker", issue = "118959")]
763765
pub fn will_wake(&self, other: &LocalWaker) -> bool {
764-
self.waker == other.waker
766+
// We optimize this by comparing vtable addresses instead of vtable contents.
767+
// This is permitted since the function is documented as best-effort.
768+
let RawWaker { data: a_data, vtable: a_vtable } = self.waker;
769+
let RawWaker { data: b_data, vtable: b_vtable } = other.waker;
770+
a_data == b_data && ptr::eq(a_vtable, b_vtable)
765771
}
766772

767773
/// Creates a new `LocalWaker` from [`RawWaker`].

0 commit comments

Comments
 (0)