Skip to content

Commit

Permalink
improve: Use pre-increment to save gas on loops (#522)
Browse files Browse the repository at this point in the history
This optimization skips storing the value before the incremental
operation as the return value of the expression is ignored.
  • Loading branch information
nicholaspai authored Jun 17, 2024
1 parent c14a801 commit 36584f9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contracts/handlers/MulticallHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ contract MulticallHandler is AcrossMessageHandler, ReentrancyGuard {

function attemptCalls(Call[] memory calls) external onlySelf {
uint256 length = calls.length;
for (uint256 i = 0; i < length; i++) {
for (uint256 i = 0; i < length; ++i) {
Call memory call = calls[i];
(bool success, ) = call.target.call{ value: call.value }(call.callData);
if (!success) revert CallReverted(i, calls);
Expand Down
2 changes: 1 addition & 1 deletion contracts/upgradeable/MultiCallerUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract MultiCallerUpgradeable {
results = new Result[](dataLength);

//slither-disable-start calls-loop
for (uint256 i = 0; i < dataLength; i++) {
for (uint256 i = 0; i < dataLength; ++i) {
// The delegatecall here is safe for the same reasons outlined in the first multicall function.
Result memory result = results[i];
//slither-disable-start low-level-calls
Expand Down

0 comments on commit 36584f9

Please sign in to comment.