Skip to content

Commit

Permalink
perf: Remove an extra heap allocation from NewLegacyDec (#19466)
Browse files Browse the repository at this point in the history
Co-authored-by: Marko <[email protected]>
  • Loading branch information
ValarDragon and tac0turtle authored Feb 19, 2024
1 parent b098abf commit 4db9838
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions math/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion math/dec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}

Expand Down

0 comments on commit 4db9838

Please sign in to comment.