Prefix increments are cheaper than postfix increments #18
Labels
bug
Something isn't working
G (Gas Optimization)
sponsor acknowledged
Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Handle
robee
Vulnerability details
Prefix increments are cheaper than postfix increments.
Further more, using unchecked {++x} is even more gas efficient, and the gas saving accumulates every iteration and can make a real change
There is no risk of overflow caused by increamenting the iteration index in for loops (the
++i
infor (uint256 i = 0; i < numIterations; ++i)
).But increments perform overflow checks that are not necessary in this case.
These functions use not using prefix increments (
++x
) or not using the unchecked keyword:The text was updated successfully, but these errors were encountered: