gas-optimizations icon indicating copy to clipboard operation
gas-optimizations copied to clipboard

Separate conditions instead of combined conditions

Open kadenzipfel opened this issue 2 years ago • 2 comments

Should add a section on this to https://github.com/kadenzipfel/gas-optimizations/blob/main/gas-saving-patterns/short-circuiting.md with this to leave the reader with a fully optimized statement

e.g. use

if (condition) {
  if (anotherCondition) {
    ...
  }
}

over

if (condition && anotherCondition) {...}

works for &&/||

kadenzipfel avatar Jul 04 '22 00:07 kadenzipfel

What would || look like?

if (condition) { ... code x }
if (anotherCondition) { ... code x }

?

har777 avatar Jul 04 '22 04:07 har777

What would || look like?

if (condition) { ... code x }
if (anotherCondition) { ... code x }

?

yep! although makes me realize that the title would no longer properly apply

kadenzipfel avatar Jul 04 '22 05:07 kadenzipfel