You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To optimize the for loop and make it consume less gas, i suggest to:
If a variable is not set/initialized, it is assumed to have the default value (0 for uint, false for bool, address(0) for address…). Explicitly initializing it with its default value is an anti-pattern and wastes gas.
Use ++i instead of i++, which is a cheaper operation (in this case there is no difference between i++ and ++i because we dont use the return value of this expression, which is the only difference between these two expression).
Yashiru
added
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
duplicate
This issue or pull request already exists
and removed
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
labels
Jun 24, 2022
To optimize the for loop and make it consume less gas, i suggest to:
If a variable is not set/initialized, it is assumed to have the default value (0 for uint, false for bool, address(0) for address…). Explicitly initializing it with its default value is an anti-pattern and wastes gas.
Use ++i instead of i++, which is a cheaper operation (in this case there is no difference between i++ and ++i because we dont use the return value of this expression, which is the only difference between these two expression).
As an example:
should be replaced with
i suggest to change the code below:
https://github.com/code-423n4/2022-06-nested/blob/main/contracts/abstracts/MixinOperatorResolver.sol#L37
https://github.com/code-423n4/2022-06-nested/blob/main/contracts/abstracts/MixinOperatorResolver.sol#L56
https://github.com/code-423n4/2022-06-nested/blob/main/contracts/OperatorResolver.sol#L40
https://github.com/code-423n4/2022-06-nested/blob/main/contracts/OperatorResolver.sol#L60
https://github.com/code-423n4/2022-06-nested/blob/main/contracts/OperatorResolver.sol#L75
https://github.com/code-423n4/2022-06-nested/blob/main/contracts/NestedFactory.sol#L124
https://github.com/code-423n4/2022-06-nested/blob/main/contracts/NestedFactory.sol#L136
https://github.com/code-423n4/2022-06-nested/blob/main/contracts/NestedFactory.sol#L196
https://github.com/code-423n4/2022-06-nested/blob/main/contracts/NestedFactory.sol#L256
https://github.com/code-423n4/2022-06-nested/blob/main/contracts/NestedFactory.sol#L315
https://github.com/code-423n4/2022-06-nested/blob/main/contracts/NestedFactory.sol#L333
https://github.com/code-423n4/2022-06-nested/blob/main/contracts/NestedFactory.sol#L369
https://github.com/code-423n4/2022-06-nested/blob/main/contracts/NestedFactory.sol#L412
https://github.com/code-423n4/2022-06-nested/blob/main/contracts/NestedFactory.sol#L651
The text was updated successfully, but these errors were encountered: