perf: Remove an extra heap allocation from NewLegacyDec (#19466)

Co-authored-by: Marko <marbar3778@yahoo.com>
This commit is contained in:
Dev Ojha 2024-02-19 03:15:57 -06:00 committed by GitHub
parent b098abfcac
commit 4db9838ae6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 1 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
* [#19466](https://github.com/cosmos/cosmos-sdk/pull/19466) Speedup `math.NewLegacyDec` by one heap allocation
* [#19467](https://github.com/cosmos/cosmos-sdk/pull/19467) Slightly speedup `math.LegacyDec` `Ceil` and `MarshalTo` methods
### Bug Fixes

View File

@ -102,8 +102,9 @@ func LegacyNewDec(i int64) LegacyDec {
// create a new Dec from integer with decimal place at prec
// CONTRACT: prec <= Precision
func LegacyNewDecWithPrec(i, prec int64) LegacyDec {
bi := big.NewInt(i)
return LegacyDec{
new(big.Int).Mul(big.NewInt(i), precisionMultiplier(prec)),
bi.Mul(bi, precisionMultiplier(prec)),
}
}