File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed
library/alloc/src/collections/btree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -13,15 +13,16 @@ trait Recover<Q: ?Sized> {
1313 fn replace ( & mut self , key : Self :: Key ) -> Option < Self :: Key > ;
1414}
1515
16+ /// Same purpose as `Option::unwrap` but doesn't always guarantee a panic
17+ /// if the option contains no value.
18+ /// SAFETY: the caller must ensure that the option contains a value.
1619#[ inline( always) ]
1720pub unsafe fn unwrap_unchecked < T > ( val : Option < T > ) -> T {
18- val. unwrap_or_else ( || {
19- if cfg ! ( debug_assertions) {
20- panic ! ( "'unchecked' unwrap on None in BTreeMap" ) ;
21- } else {
22- unsafe {
23- core:: intrinsics:: unreachable ( ) ;
24- }
25- }
26- } )
21+ if cfg ! ( debug_assertions) {
22+ val. expect ( "'unchecked' unwrap on None in BTreeMap" )
23+ } else {
24+ val. unwrap ( )
25+ // val.unwrap_or_else(|| unsafe { core::hint::unreachable_unchecked() })
26+ // ...is considerably slower
27+ }
2728}
You can’t perform that action at this time.
0 commit comments