Closed chasebrownn closed 5 months ago
The referenced code block is inefficient and can be removed in favour of an else clause that always increments the i iterator.
else
i
for (uint256 i; i < length;) { address delegator = delegators[i]; if (isExpiredDelegator(delegator)) { // call withdrawDelegatedToken (bool success,) = delegator.call(abi.encodeWithSignature("withdrawDelegatedToken()")); require(success, "withdraw unsuccessful"); // delete delegator from contract delete isDelegator[delegator]; delete delegatorExpiration[delegator]; delegators[i] = delegators[length - 1]; delegators.pop(); --length; emit DelegatorDeleted(delegator); } if (i < length) { if (!isExpiredDelegator(delegators[i])) { unchecked { ++i; } } } }
We advise the aforementioned else clause to be introduced to the first if conditional within the for loop, optimizing the code's clarity and gas cost.
if
for
Acknowledged
DFY-03C: Optimization of Code Structure
Description:
The referenced code block is inefficient and can be removed in favour of an
else
clause that always increments thei
iterator.Example:
Recommendation:
We advise the aforementioned
else
clause to be introduced to the firstif
conditional within thefor
loop, optimizing the code's clarity and gas cost.