File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -1359,7 +1359,14 @@ trait RcBoxPtr<T: ?Sized> {
13591359
13601360 #[ inline]
13611361 fn inc_strong ( & self ) {
1362- self . inner ( ) . strong . set ( self . strong ( ) . checked_add ( 1 ) . unwrap_or_else ( || unsafe { abort ( ) } ) ) ;
1362+ // We want to abort on overflow instead of dropping the value.
1363+ // The reference count will never be zero when this is called;
1364+ // nevertheless, we insert an abort here to hint LLVM at
1365+ // an otherwise missied optimization.
1366+ if self . strong ( ) == 0 || self . strong ( ) == usize:: max_value ( ) {
1367+ unsafe { abort ( ) ; }
1368+ }
1369+ self . inner ( ) . strong . set ( self . strong ( ) + 1 ) ;
13631370 }
13641371
13651372 #[ inline]
@@ -1374,7 +1381,14 @@ trait RcBoxPtr<T: ?Sized> {
13741381
13751382 #[ inline]
13761383 fn inc_weak ( & self ) {
1377- self . inner ( ) . weak . set ( self . weak ( ) . checked_add ( 1 ) . unwrap_or_else ( || unsafe { abort ( ) } ) ) ;
1384+ // We want to abort on overflow instead of dropping the value.
1385+ // The reference count will never be zero when this is called;
1386+ // nevertheless, we insert an abort here to hint LLVM at
1387+ // an otherwise missied optimization.
1388+ if self . weak ( ) == 0 || self . weak ( ) == usize:: max_value ( ) {
1389+ unsafe { abort ( ) ; }
1390+ }
1391+ self . inner ( ) . weak . set ( self . weak ( ) + 1 ) ;
13781392 }
13791393
13801394 #[ inline]
You can’t perform that action at this time.
0 commit comments