File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -390,6 +390,11 @@ impl<T> Arc<T> {
390
390
pub unsafe fn get_mut_unchecked ( this : & mut Self ) -> & mut T {
391
391
unsafe { & mut * ( * this. ptr . as_ptr ( ) ) . data . get ( ) }
392
392
}
393
+
394
+ // Non-inlined part of `drop`. Just invokes the destructor.
395
+ unsafe fn drop_slow ( & mut self ) {
396
+ let _ = Box :: from_raw ( self . ptr . as_ptr ( ) ) ;
397
+ }
393
398
}
394
399
395
400
impl < T : Clone > Arc < T > {
@@ -550,9 +555,11 @@ impl<T> Drop for Arc<T> {
550
555
if self . inner ( ) . counter . fetch_sub ( 1 , Ordering :: Release ) != 1 {
551
556
return ;
552
557
}
558
+
553
559
fence ( Ordering :: Acquire ) ;
560
+
554
561
// SAFETY: this is the last owner of the ptr, it is safe to drop data
555
- unsafe { Box :: from_raw ( self . ptr . as_ptr ( ) ) } ;
562
+ unsafe { self . drop_slow ( ) } ;
556
563
}
557
564
}
558
565
Original file line number Diff line number Diff line change @@ -311,6 +311,11 @@ impl<T> Rc<T> {
311
311
Err ( this)
312
312
}
313
313
}
314
+
315
+ // Non-inlined part of `drop`. Just invokes the destructor.
316
+ unsafe fn drop_slow ( & mut self ) {
317
+ let _ = Box :: from_raw ( self . ptr . as_mut ( ) ) ;
318
+ }
314
319
}
315
320
316
321
impl < T : Clone > Rc < T > {
@@ -470,7 +475,7 @@ impl<T> Drop for Rc<T> {
470
475
let value = value. wrapping_sub ( 1 ) ;
471
476
counter. set ( value) ;
472
477
} else {
473
- unsafe { Box :: from_raw ( self . ptr . as_mut ( ) ) } ;
478
+ unsafe { self . drop_slow ( ) } ;
474
479
}
475
480
}
476
481
}
You can’t perform that action at this time.
0 commit comments