@Thunderbrd Did you know that "
std::max(0, iModifier);" is usually slower to process than "
if (iModifier < 0) iModifier = 0;" ?
(
Edit: Depends a lot on the compiler of the language in question, smart compilers will write the same code for both)
Even more so in this example where variables don't have to be changed:
return std::max(0, iModifier);
vs
if (iModifier > 0) return iModifier;
return 0;
I don't know exactly the impact in c++ code, but in python code it's around 50 times faster. (
Edit: No impact it seems in c++ code, python is uncompiled code, so what you write is what you get quite literally).
In this piece of code we never want to return 0 ever as it breaks the AI flavour valuation code completely.
It should rather be "
return std::max(50, iModifier);"
Additionally, it is not possible for iModifier to be smaller than 50 in this piece of code; so there is no need for the max function call here at all.
Today's small performance tip. ^^
Edit: Did some reading, seems like modern compilers generate the same code for both versions, so it doesn't matter, as the compiler will pretty much translate an std::max( function call into an effective comparison code (with the assembler equivalent of an if statement) instead without the function call overhead. Didn't know that compilers changed code to such an extent during interpretation for cases like this.