File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -136,6 +136,15 @@ impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for RawWaker {
136136#[ inline( always) ]
137137fn raw_waker < W : Wake + Send + Sync + ' static > ( waker : Arc < W > ) -> RawWaker {
138138 // Increment the reference count of the arc to clone it.
139+ //
140+ // The #[inline(always)] is to ensure that raw_waker and clone_waker are
141+ // always generated in the same code generation unit as one another, and
142+ // therefore that the structurally identical const-promoted RawWakerVTable
143+ // within both functions is deduplicated at LLVM IR code generation time.
144+ // This allows optimizing Waker::will_wake to a single pointer comparison of
145+ // the vtable pointers, rather than comparing all four function pointers
146+ // within the vtables.
147+ #[ inline( always) ]
139148 unsafe fn clone_waker < W : Wake + Send + Sync + ' static > ( waker : * const ( ) ) -> RawWaker {
140149 unsafe { Arc :: increment_strong_count ( waker as * const W ) } ;
141150 RawWaker :: new (
@@ -304,6 +313,10 @@ impl<W: LocalWake + 'static> From<Rc<W>> for RawWaker {
304313#[ inline( always) ]
305314fn local_raw_waker < W : LocalWake + ' static > ( waker : Rc < W > ) -> RawWaker {
306315 // Increment the reference count of the Rc to clone it.
316+ //
317+ // Refer to the comment on raw_waker's clone_waker regarding why this is
318+ // always inline.
319+ #[ inline( always) ]
307320 unsafe fn clone_waker < W : LocalWake + ' static > ( waker : * const ( ) ) -> RawWaker {
308321 unsafe { Rc :: increment_strong_count ( waker as * const W ) } ;
309322 RawWaker :: new (
You can’t perform that action at this time.
0 commit comments