perf: Remove unneeded cmp in Ceil and marshalTo (#19467)

This commit is contained in:
Dev Ojha 2024-02-19 02:21:47 -06:00 committed by GitHub
parent 16b19638ef
commit 0f113520f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 5 deletions

View File

@ -43,6 +43,7 @@ Ref: https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.j
* [#18874](https://github.com/cosmos/cosmos-sdk/pull/18874) Speedup `math.Int.Mul` by removing a duplicate overflow check
* [#19386](https://github.com/cosmos/cosmos-sdk/pull/19386) Speedup `math.Int` overflow checks
* [#19467](https://github.com/cosmos/cosmos-sdk/pull/19467) Slightly speedup `math.LegacyDec` `Ceil` and `MarshalTo` methods
### Bug Fixes

View File

@ -734,11 +734,9 @@ func (d LegacyDec) Ceil() LegacyDec {
quo, rem = quo.QuoRem(tmp, precisionReuse, rem)
// no need to round with a zero remainder regardless of sign
if rem.Cmp(zeroInt) == 0 {
if rem.Sign() == 0 {
return LegacyNewDecFromBigInt(quo)
}
if rem.Sign() == -1 {
} else if rem.Sign() == -1 {
return LegacyNewDecFromBigInt(quo)
}
@ -847,7 +845,7 @@ func (d *LegacyDec) MarshalTo(data []byte) (n int, err error) {
i = new(big.Int)
}
if i.Cmp(zeroInt) == 0 {
if i.Sign() == 0 {
copy(data, []byte{0x30})
return 1, nil
}