File tree Expand file tree Collapse file tree 1 file changed +28
-4
lines changed Expand file tree Collapse file tree 1 file changed +28
-4
lines changed Original file line number Diff line number Diff line change 1
- // FIXME: Branch prediction hint. This is currently only available on nightly
2
- // but it consistently improves performance by 10-15%.
3
- #[ cfg( not( feature = "nightly" ) ) ]
4
- pub ( crate ) use core:: convert:: { identity as likely, identity as unlikely} ;
1
+ // FIXME: Replace with `core::hint::{likely, unlikely}` once they are stable.
5
2
#[ cfg( feature = "nightly" ) ]
6
3
pub ( crate ) use core:: intrinsics:: { likely, unlikely} ;
7
4
5
+ #[ cfg( not( feature = "nightly" ) ) ]
6
+ #[ inline( always) ]
7
+ #[ cold]
8
+ fn cold_path ( ) { }
9
+
10
+ #[ cfg( not( feature = "nightly" ) ) ]
11
+ #[ inline( always) ]
12
+ pub ( crate ) fn likely ( b : bool ) -> bool {
13
+ if b {
14
+ true
15
+ } else {
16
+ cold_path ( ) ;
17
+ false
18
+ }
19
+ }
20
+
21
+ #[ cfg( not( feature = "nightly" ) ) ]
22
+ #[ inline( always) ]
23
+ pub ( crate ) fn unlikely ( b : bool ) -> bool {
24
+ if b {
25
+ cold_path ( ) ;
26
+ true
27
+ } else {
28
+ false
29
+ }
30
+ }
31
+
8
32
// FIXME: use strict provenance functions once they are stable.
9
33
// Implement it with a transmute for now.
10
34
#[ inline( always) ]
You can’t perform that action at this time.
0 commit comments