From 88a3f957151b5b77cc19575dc987fd28f0fcd486 Mon Sep 17 00:00:00 2001 From: Mathis Gontier Delaunay <74971347+MathisGD@users.noreply.github.com> Date: Fri, 4 Nov 2022 00:57:56 +0100 Subject: [PATCH] Optimize condition in _disableInitializers (#3787) --- CHANGELOG.md | 1 + contracts/proxy/utils/Initializable.sol | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3093bf90ec..8c2f9f92ba5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * `ReentrancyGuard`: Add a `_reentrancyGuardEntered` function to expose the guard status. ([#3714](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3714)) * `ERC20Votes`: optimize by using unchecked arithmetic. ([#3748](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3748)) + * `Initializable`: optimize `_disableInitializers` by using `!=` instead of `<`. ([#3787](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3787)) ## Unreleased diff --git a/contracts/proxy/utils/Initializable.sol b/contracts/proxy/utils/Initializable.sol index 51d4be7f4e5..d0110f0fc68 100644 --- a/contracts/proxy/utils/Initializable.sol +++ b/contracts/proxy/utils/Initializable.sol @@ -143,7 +143,7 @@ abstract contract Initializable { */ function _disableInitializers() internal virtual { require(!_initializing, "Initializable: contract is initializing"); - if (_initialized < type(uint8).max) { + if (_initialized != type(uint8).max) { _initialized = type(uint8).max; emit Initialized(type(uint8).max); }