File tree 1 file changed +13
-0
lines changed
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 {
136
136
#[ inline( always) ]
137
137
fn raw_waker < W : Wake + Send + Sync + ' static > ( waker : Arc < W > ) -> RawWaker {
138
138
// 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) ]
139
148
unsafe fn clone_waker < W : Wake + Send + Sync + ' static > ( waker : * const ( ) ) -> RawWaker {
140
149
unsafe { Arc :: increment_strong_count ( waker as * const W ) } ;
141
150
RawWaker :: new (
@@ -304,6 +313,10 @@ impl<W: LocalWake + 'static> From<Rc<W>> for RawWaker {
304
313
#[ inline( always) ]
305
314
fn local_raw_waker < W : LocalWake + ' static > ( waker : Rc < W > ) -> RawWaker {
306
315
// 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) ]
307
320
unsafe fn clone_waker < W : LocalWake + ' static > ( waker : * const ( ) ) -> RawWaker {
308
321
unsafe { Rc :: increment_strong_count ( waker as * const W ) } ;
309
322
RawWaker :: new (
You can’t perform that action at this time.
0 commit comments