perf: Speedup DecCoin.Sort() when coins is of length 1 (#18888)
This commit is contained in:
@@ -54,6 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### Improvements
|
||||
|
||||
* (types) [#18888](https://github.com/cosmos/cosmos-sdk/pull/18888) Speedup DecCoin.Sort() if len(coins) <= 1
|
||||
* (types) [#18875](https://github.com/cosmos/cosmos-sdk/pull/18875) Speedup coins.Sort() if len(coins) <= 1
|
||||
* (client/keys) [#18745](https://github.com/cosmos/cosmos-sdk/pull/18745) Improve `<appd> keys export` and `<appd> keys mnemonic` by adding --yes option to skip interactive confirmation.
|
||||
* (client/keys) [#18743](https://github.com/cosmos/cosmos-sdk/pull/18743) Improve `<appd> keys add -i` by hiding inputting of bip39 passphrase.
|
||||
|
||||
+6
-1
@@ -615,7 +615,12 @@ func (coins DecCoins) Swap(i, j int) { coins[i], coins[j] = coins[j], coins[i] }
|
||||
|
||||
// Sort is a helper function to sort the set of decimal coins in-place.
|
||||
func (coins DecCoins) Sort() DecCoins {
|
||||
sort.Sort(coins)
|
||||
// sort.Sort(coins) does a costly runtime copy as part of `runtime.convTSlice`
|
||||
// So we avoid this heap allocation if len(coins) <= 1. In the future, we should hopefully find
|
||||
// a strategy to always avoid this.
|
||||
if len(coins) > 1 {
|
||||
sort.Sort(coins)
|
||||
}
|
||||
return coins
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user