Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ifs vs mappings in UniswapConfig.sol #146

Closed
RickieRao opened this issue Dec 10, 2020 · 1 comment
Closed

ifs vs mappings in UniswapConfig.sol #146

RickieRao opened this issue Dec 10, 2020 · 1 comment

Comments

@RickieRao
Copy link
Contributor

Hi guys, great work, I am currently checking out the contracts code,

and wondering if it is better to have many if conditions like:

function getUnderlyingIndex(address underlying) internal view returns (uint) {
if (underlying == underlying00) return 0;
if (underlying == underlying01) return 1;
if (underlying == underlying02) return 2;
if (underlying == underlying03) return 3;
if (underlying == underlying04) return 4;
if (underlying == underlying05) return 5;
if (underlying == underlying06) return 6;
...

for underlying, symbols, cTokens
than having mappings like(pseudo-code here):

underlyingAddress => TokenConfig;
symbols => TokenConfig;
cTokenAddress => TokenConfig;

i mean using ifs means you will need to go through 0 - 5 to get the 06 index every time right?

I'm just green in solidity coding, so hoping to get some insights here.

Many thanks.

@coburncoburn
Copy link
Contributor

in order to use immutable values rather than storage reads, the if statements are necessary. This makes for lower gas costs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants