Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Adds a likely! and unlikely! macros to optimize the compiler generation of if statements

License

NotificationsYou must be signed in to change notification settings

lemonrock/likely

Repository files navigation

likely is a rust crate used to provide macro wrappers around the intrinsics::std::intrinsic::likely and::std::intrinsic::unlikely, which themselves are hints to the CPU's branch predictor.

These hints should only be used when the vast majority of cases would satisfy them. A typicaly example might be a highly unusual error condition, or an extreme value or outlier in a range. Another common scenario is dealing with return codes from common libc functions, many of which are highly unlikely to occur (egEINVAL for many such functions).

Note that using these macro wrappers requires compiling with nightly.

Using It.

Firstly, Include it

To include it, add the following to yourCargo.toml:-

[dependencies]likely ="^0.1"

In your crate'slib.rs, add:-

`#![feature(core_intrinsics)]`...#[macro_use]externcrate likely;

Secondly, use it withif statements

fnexample(age:u8){iflikely!(age <=70){println!("Not yet entitled to this welfare benefit")}elseifunlikely!(age ==99){println!("You are entitled to a birthday card from the Queen for your next birthday")}}

Licensing

The license for this project is MIT.

About

Adds a likely! and unlikely! macros to optimize the compiler generation of if statements

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp