6529-Collections / nftdelegation

Delegation contract
MIT License
16 stars 7 forks source link

Refactor conditionals to reduce code size, improve readability #41

Closed brookr closed 1 year ago

brookr commented 1 year ago

Two meaningful refactors here:

Clean up _allToken checks...

Since this code is checking true / false and then inserting bool literal true / false respecitvely, we can just use the variable.

the only other differnce between the 2 branches of the conditiional is to ensure _tokenId is 0 when _allTokens is true. We can handle that with a conditional assignment of 0, or keeping the existing value on _tokenId.

Refactor unneeded if statements prior to loops...

When we are looping over the something based on the length (how many hashes), we don't need to check if it's greater than 0... If it is 0, the for loop won't execute at all anyway.

This also simplified the logic and readability of the return pattern: just return from in the loop if true, and otherwise return false.

Eliminating the status variable reduces storage and complexit, and improves readability.

a2rocket commented 1 year ago

contract is finalized.