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

UniswapV2Router01 and 02: replace "if (A && B)" to save gas fees #162

Open
BurtonQin opened this issue Jun 29, 2023 · 1 comment
Open

UniswapV2Router01 and 02: replace "if (A && B)" to save gas fees #162

BurtonQin opened this issue Jun 29, 2023 · 1 comment

Comments

@BurtonQin
Copy link

The solidity compiler generates more code for “if (A && B) {}” than for “if (A) {if (B) {} }”.
Our experiment shows that switching from “if (A && B) {}” to “if (A) {if (B) {} }” can save gas fees.

There are two such cases:

if (reserveA == 0 && reserveB == 0) {

if (reserveA == 0 && reserveB == 0) {

Replacing

if (reserveA == 0 && reserveB == 0) {

with

if (reserveA == 0) {
    if (reserveB == 0) {

can save gas fees and does not hurt code readability.

@Divy027
Copy link

Divy027 commented Jul 4, 2023

can I help to solve this issues?

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