Cache array length outside of loop
If not cached, the solidity compiler will always read the length of the array during each iteration. That is, if it is a storage array, this is an extra sload operation (100 additional extra gas for each iteration except for the first) and if it is a memory array, this is an extra mload operation.
Instances (2):
(3 additional gas for each iteration except for the first)
4naly3er
Caching the array length (in stack):
uint length = arr.length;
for (uint i = 0; i < length; i++) {
}
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.