Skip to content

likely/unlikely for if () #1342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shawnl opened this issue Aug 6, 2018 · 6 comments
Closed

likely/unlikely for if () #1342

shawnl opened this issue Aug 6, 2018 · 6 comments

Comments

@shawnl
Copy link
Contributor

shawnl commented Aug 6, 2018

if (likely a < 0)
    foo;

If (unlikely b < 0)
    bar;

like in linux https://github.com/torvalds/linux/blob/master/include/linux/compiler.h#L39

@PavelVozenilek
Copy link

I'd proposed this in #489, with if+ and if-. More wordy or complicated syntax wouldn't be worth the trouble.

@shawnl
Copy link
Contributor Author

shawnl commented Aug 6, 2018

if+ and if- is nice, especially as it corresponds to "closing" and "expanding" symbols. Closing

@shawnl shawnl closed this as completed Aug 6, 2018
@BarabasGitHub
Copy link
Contributor

BarabasGitHub commented Aug 7, 2018 via email

@shawnl
Copy link
Contributor Author

shawnl commented Aug 7, 2018

However "likely" and "unlikely" are in the wrong place here. They need to be the same as adding "comptime" to an expression

@PavelVozenilek
Copy link

@BarabasGitHub: if likely/unlikely functionality is expected to have measurable effect on performance, it should be used frequently. if+/if- doesn't clutter visually the code, unlike the alternatives. If they are used frequently, people will internalize their meaning quickly.

@shawnl
Copy link
Contributor Author

shawnl commented Aug 7, 2018

yeah but likely/unlikely would work the same as comptime, which is nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants