[英]likely/unlikely instead of if/else
I replaced one occurrence of if/else
with likely/unlikely
which given me some improvement in performance as this executes many times. 我用
likely/unlikely
替换了一次if/else
,这给了我一些性能上的改进,因为它执行了很多次。 Now I would like to change all the occurrences of if/else
with likely/unlikely
. 现在我想改变所有出现
if/else
与likely/unlikely
。 I use this code on only one target/OS. 我只在一个目标/操作系统上使用此代码。
Does this have any drawbacks to replace all if/else
's ? 这有什么缺点来替换所有
if/else
的吗?
As likely
and unlikely
usually are macros defined in some library and expanding to some __buildin...
-commands, the only drawback you can expect is, that this might be harder to read. 由于
likely
并且unlikely
通常是某些库中定义的宏并扩展到某些__buildin...
命令,因此您可以预期的唯一缺点是,这可能更难以阅读。
Edit: But please - use it only in that cases, where you really expect a condition to be more likely than the alternative! 编辑:但请 - 只在那种情况下使用它,你真的期望条件比替代品更可能!
If some platform / library does not implement likely
and unlikely
or the implementation is wrong, you can easily #define
it empty by yourself. 如果某个平台/库没有实现
likely
和unlikely
或实现错误,您可以轻松#define
它自己空。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.