Closed chasebrownn closed 5 months ago
The referenced operation will be redundantly performed when i is equal to len - 1.
i
len - 1
function removeRevenueToken(address _revToken) external onlyOwner { require(isRevToken[_revToken], "token not added"); isRevToken[_revToken] = false; uint256 len = revenueTokens.length; for (uint256 i; i < len;) { if (revenueTokens[i] == _revToken) { revenueTokens[i] = revenueTokens[len - 1]; revenueTokens.pop(); break; } unchecked { ++i; } } emit RevTokenRemoved(_revToken); }
We advise the statement to be wrapped in an if conditional that prevents this case, optimizing the code's gas cost.
if
Acknowledged
RDR-02C: Inefficient Array Shift Operation
Description:
The referenced operation will be redundantly performed when
i
is equal tolen - 1
.Example:
Recommendation:
We advise the statement to be wrapped in an
if
conditional that prevents this case, optimizing the code's gas cost.