Please consider the following piece of code:
void error_handling();
bool method_impl();
bool method()
{
const bool res = method_impl();
if (res == false) {
error_handling();
return false;
}
return true;
}
I know method_impl() will return true 99.999% (yes, three decimal places) of the time, but my compiler doesn't. method() is partially critical in term of time-consumption.
- Should I rewrite
method()(and make it less readable) to ensure a jump may only occur whenmethod_impl()returnsfalse? If yes, how? - Should I let the compiler do the work for me?
- Should I let the branch prediction of my CPU do the work for me?