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

Optimize condition in _disableInitializers #3787

Merged
merged 1 commit into from
Nov 3, 2022

Conversation

MathisGD
Copy link
Contributor

@MathisGD MathisGD commented Oct 27, 2022

Minor optimization (2 gas) of _disableInitializers in Initializable.

A JUMP should happen if the condition is false. With != it requires only EQ (3 gas) while with < it requires LT + IZERO (3 + 2 gas).

PR Checklist

  • Tests
  • Documentation
  • Changelog entry

@Amxx Amxx requested a review from frangio October 31, 2022 09:47
@frangio frangio changed the title perf: save one ISZERO in _disableInitializers Optimize condition in _disableInitializers Nov 3, 2022
Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @MathisGD. I'm really not happy that Solidity doesn't do this minor optimization on its own.

@frangio frangio merged commit 88a3f95 into OpenZeppelin:master Nov 3, 2022
@gitpoap-bot
Copy link

gitpoap-bot bot commented Nov 3, 2022

Congrats, your important contribution to this open-source project has earned you a GitPOAP!

GitPOAP: 2022 OpenZeppelin Contracts Contributor:

GitPOAP: 2022 OpenZeppelin Contracts Contributor GitPOAP Badge

Head to gitpoap.io & connect your GitHub account to mint!

Learn more about GitPOAPs here.

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

Successfully merging this pull request may close these issues.

None yet

2 participants