perf: Remove duplicate overflow check from int.Mul (#18874)

This commit is contained in:
Dev Ojha 2023-12-26 06:04:10 -06:00 committed by GitHub
parent bd04173012
commit 0c6b6d49cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 5 deletions

View File

@ -41,6 +41,8 @@ Ref: https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.j
* [#18421](https://github.com/cosmos/cosmos-sdk/pull/18421) Add mutative api for `LegacyDec.BigInt()`.
* [#18874](https://github.com/cosmos/cosmos-sdk/pull/18874) Speedup `math.Int.Mul` by removing a duplicate overflow check
### Bug Fixes
* [#18519](https://github.com/cosmos/cosmos-sdk/pull/18519) Prevent Overflow in `Dec.Ceil()`.

View File

@ -333,12 +333,8 @@ func (i Int) MulRaw(i2 int64) Int {
// SafeMul multiples Int from another and returns an error if overflow
func (i Int) SafeMul(i2 Int) (res Int, err error) {
// Check overflow
if i.i.BitLen()+i2.i.BitLen()-1 > MaxBitLen {
return Int{}, ErrIntOverflow
}
res = Int{mul(i.i, i2.i)}
// Check overflow if sign of both are same
// Check overflow
if res.i.BitLen() > MaxBitLen {
return Int{}, ErrIntOverflow
}