Optimize Math.max and SignedMath.max (#3679)

Co-authored-by: Daniel Liu <liudaniel@qq.com>
pull/3683/head
Daniel Liu 2 years ago committed by GitHub
parent 84fafa7832
commit 005a35b02a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      contracts/utils/math/Math.sol
  3. 2
      contracts/utils/math/SignedMath.sol

@ -29,6 +29,7 @@
* `Arrays`: Add `unsafeAccess` functions that allow reading and writing to an element in a storage array bypassing Solidity's "out-of-bounds" check. ([#3589](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3589)) * `Arrays`: Add `unsafeAccess` functions that allow reading and writing to an element in a storage array bypassing Solidity's "out-of-bounds" check. ([#3589](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3589))
* `Strings`: optimize `toString`. ([#3573](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3573)) * `Strings`: optimize `toString`. ([#3573](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3573))
* `Ownable2Step`: extension of `Ownable` that makes the ownership transfers a two step process. ([#3620](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3620)) * `Ownable2Step`: extension of `Ownable` that makes the ownership transfers a two step process. ([#3620](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3620))
* `Math` and `SignedMath`: optimize function `max` by using `>` instead of `>=`. ([#3679](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3679))
### Breaking changes ### Breaking changes

@ -17,7 +17,7 @@ library Math {
* @dev Returns the largest of two numbers. * @dev Returns the largest of two numbers.
*/ */
function max(uint256 a, uint256 b) internal pure returns (uint256) { function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b; return a > b ? a : b;
} }
/** /**

@ -11,7 +11,7 @@ library SignedMath {
* @dev Returns the largest of two signed numbers. * @dev Returns the largest of two signed numbers.
*/ */
function max(int256 a, int256 b) internal pure returns (int256) { function max(int256 a, int256 b) internal pure returns (int256) {
return a >= b ? a : b; return a > b ? a : b;
} }
/** /**

Loading…
Cancel
Save