perf: add AmountOfNoValidation for DecCoins (#18440)
This commit is contained in:
parent
89296ccdd3
commit
b7fb2928e1
@ -53,6 +53,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### Improvements
|
||||
|
||||
* (types) [#18440](https://github.com/cosmos/cosmos-sdk/pull/18440) Add `AmountOfNoValidation` to `sdk.DecCoins`.
|
||||
* (x/gov) [#18428](https://github.com/cosmos/cosmos-sdk/pull/18428) Extend governance config
|
||||
* (x/gov) [#18189](https://github.com/cosmos/cosmos-sdk/pull/18189) Limit the accepted deposit coins for a proposal to the minimum proposal deposit denoms.
|
||||
* (x/gov) [#18025](https://github.com/cosmos/cosmos-sdk/pull/18025) Improve `<appd> q gov proposer` by querying directly a proposal instead of tx events. It is an alias of `q gov proposal` as the proposer is a field of the proposal.
|
||||
|
||||
@ -451,10 +451,16 @@ func (coins DecCoins) Empty() bool {
|
||||
return len(coins) == 0
|
||||
}
|
||||
|
||||
// AmountOf returns the amount of a denom from deccoins
|
||||
// AmountOf returns the amount of a denom from deccoins. It panics if the denom
|
||||
// is invalid.
|
||||
func (coins DecCoins) AmountOf(denom string) math.LegacyDec {
|
||||
mustValidateDenom(denom)
|
||||
return coins.AmountOfNoValidation(denom)
|
||||
}
|
||||
|
||||
// AmountOfNoValidation returns the amount of a denom from deccoins without checking
|
||||
// the correctness of the denom.
|
||||
func (coins DecCoins) AmountOfNoValidation(denom string) math.LegacyDec {
|
||||
switch len(coins) {
|
||||
case 0:
|
||||
return math.LegacyZeroDec()
|
||||
@ -472,11 +478,11 @@ func (coins DecCoins) AmountOf(denom string) math.LegacyDec {
|
||||
|
||||
switch {
|
||||
case denom < coin.Denom:
|
||||
return coins[:midIdx].AmountOf(denom)
|
||||
return coins[:midIdx].AmountOfNoValidation(denom)
|
||||
case denom == coin.Denom:
|
||||
return coin.Amount
|
||||
default:
|
||||
return coins[midIdx+1:].AmountOf(denom)
|
||||
return coins[midIdx+1:].AmountOfNoValidation(denom)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user