code-423n4 / 2021-11-streaming-findings

0 stars 0 forks source link

`++i` is more efficient than `i++` #264

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

WatchPug

Vulnerability details

Using ++i is more gas efficient than i++, especially in a loop.

We suggest using unchecked {++i} to even better gas performance.

For example:

https://github.com/code-423n4/2021-11-streaming/blob/56d81204a00fc949d29ddd277169690318b36821/Streaming/src/LockeERC20.sol#L222-L225

while (j != 0) {
    len++;
    j /= 10;
}
0xean commented 2 years ago

dupe of #263 (same optimization)