Skip to content

Commit 4db9838

Browse files
perf: Remove an extra heap allocation from NewLegacyDec (#19466)
Co-authored-by: Marko <marbar3778@yahoo.com>
1 parent b098abf commit 4db9838

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

math/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Ref: https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.j
4343

4444
* [#18874](https://github.com/cosmos/cosmos-sdk/pull/18874) Speedup `math.Int.Mul` by removing a duplicate overflow check
4545
* [#19386](https://github.com/cosmos/cosmos-sdk/pull/19386) Speedup `math.Int` overflow checks
46+
* [#19466](https://github.com/cosmos/cosmos-sdk/pull/19466) Speedup `math.NewLegacyDec` by one heap allocation
4647
* [#19467](https://github.com/cosmos/cosmos-sdk/pull/19467) Slightly speedup `math.LegacyDec` `Ceil` and `MarshalTo` methods
4748

4849
### Bug Fixes

math/dec.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ func LegacyNewDec(i int64) LegacyDec {
102102
// create a new Dec from integer with decimal place at prec
103103
// CONTRACT: prec <= Precision
104104
func LegacyNewDecWithPrec(i, prec int64) LegacyDec {
105+
bi := big.NewInt(i)
105106
return LegacyDec{
106-
new(big.Int).Mul(big.NewInt(i), precisionMultiplier(prec)),
107+
bi.Mul(bi, precisionMultiplier(prec)),
107108
}
108109
}
109110

0 commit comments

Comments
 (0)