sherlock-audit / 2024-08-flayer-judging

2 stars 0 forks source link

Happy Green Chimpanzee - cache the length of loop to save gas #801

Closed sherlock-admin4 closed 1 month ago

sherlock-admin4 commented 1 month ago

Happy Green Chimpanzee

Low/Info

cache the length of loop to save gas

Summary

it is better to cache the length of list rather then loading it from the variable

Vulnerability Detail

in a lot of area where for loop is used , it is going to use like this array.length , it costs a alot more gas than expected

Impact

cause a lot more gas

Code Snippet

        for (uint i; i < _createListings.length; ++i) {

Manual Review

Recommendation

uint len = _createListings.length;

- for (uint i; i < _createListings.length; ++i)
+ for (uint i; i < len; ++i)