File tree 1 file changed +16
-2
lines changed
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> {
1359
1359
1360
1360
#[ inline]
1361
1361
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 ) ;
1363
1370
}
1364
1371
1365
1372
#[ inline]
@@ -1374,7 +1381,14 @@ trait RcBoxPtr<T: ?Sized> {
1374
1381
1375
1382
#[ inline]
1376
1383
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 ) ;
1378
1392
}
1379
1393
1380
1394
#[ inline]
You can’t perform that action at this time.
0 commit comments