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> {
13
13
fn replace ( & mut self , key : Self :: Key ) -> Option < Self :: Key > ;
14
14
}
15
15
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.
16
19
#[ inline( always) ]
17
20
pub 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
+ }
27
28
}
You can’t perform that action at this time.
0 commit comments