File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -264,3 +264,39 @@ pub const SUCCESS: u64 = 0;
264264
265265/// The result of a program execution.
266266pub type ProgramResult = Result < ( ) , program_error:: ProgramError > ;
267+
268+ /// Module with functions to provide hints to the compiler about how code
269+ /// should be optimized.
270+ pub mod hint {
271+ /// A "dummy" function with a hint to the compiler that it is unlikely to be
272+ /// called.
273+ ///
274+ /// This function is used as a hint to the compiler to optimize other code paths
275+ /// instead of the one where the function is used.
276+ #[ cold]
277+ pub const fn cold_path ( ) { }
278+
279+ /// Return the given `bool` value with a hint to the compiler that `true` is the
280+ /// likely case.
281+ #[ inline( always) ]
282+ pub const fn likely ( b : bool ) -> bool {
283+ if b {
284+ true
285+ } else {
286+ cold_path ( ) ;
287+ false
288+ }
289+ }
290+
291+ /// Return a given `bool` value with a hint to the compiler that `false` is the
292+ /// likely case.
293+ #[ inline( always) ]
294+ pub const fn unlikely ( b : bool ) -> bool {
295+ if b {
296+ cold_path ( ) ;
297+ true
298+ } else {
299+ false
300+ }
301+ }
302+ }
You can’t perform that action at this time.
0 commit comments