Some people may find the following useful information (the following code should be considered in high-performance programs, where each synchronization cycle matters, and the goal here is to show alternative methods, I would not use it in this particular situation).
If you need fast code without branches, you can implement int multiplication with boolean using bitwise operators.
bool b = true; int number = 10; number = b*number;
can be optimized for:
number = (-b & number);
If b is true , then -b is -1 , and all bits are set to 1 . Otherwise, all bits are 0 .
Boolean NOT ( !b ) can be implemented with XOR'ing b with 1 ( b^1 ).
Therefore, in your case, we get the following expression:
height = (-(legendText->isEmpty()^1) & height);
Maciej Oct 23 '15 at 23:42 2015-10-23 23:42
source share