LoneGazebo / Community-Patch-DLL

Community Patch for Civilization V - Brave New World
Other
285 stars 158 forks source link

postfixOperator #11097

Closed JohnsterID closed 3 months ago

JohnsterID commented 3 months ago

Change some of the cppcheck identified postfix operators to predix operators. Both builds work.

Id: postfixOperator
CWE: 398
Prefix ++/-- operators should be preferred for non-primitive types. Pre-increment/decrement can be more efficient than post-increment/decrement. Post-increment/decrement usually involves keeping a copy of the previous value around and adds a little extra code.

The change is straightforward because the behavior of prefix (++it) and postfix (it++) increment operators is largely similar in most contexts, especially when used in loops. The key distinction is that it++ creates a copy of the iterator before incrementing, which can be marginally less efficient than ++it, which directly increments the iterator without creating a copy.

Using the prefix increment (++itr_quest) rather than the postfix increment (itr_quest++) in a loop is typically more efficient, especially for non-primitive types such as iterators. This efficiency arises because postfix incrementation involves creating a temporary copy of the iterator before performing the increment, whereas prefix incrementation directly modifies the iterator itself. While the change generally results in slightly more efficient code, the overall behavior within the loop remains consistent.