Skip to content

Commit

Permalink
perf: Speedup coins.AmountOf() by removing many regex calls (backport c…
Browse files Browse the repository at this point in the history
…osmos#10021) (cosmos#10166)

* perf: Speedup coins.AmountOf() by removing many regex calls (cosmos#10021)

(cherry picked from commit ed35bfd)

* fix conflict

* fix changelog

Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
Co-authored-by: Robert Zaremba <robert@zaremba.ch>
  • Loading branch information
3 people authored and Eengineer1 committed Aug 25, 2022
1 parent 3919443 commit 4df15b5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### Improvements
* (types) [\#10021](https://github.com/cosmos/cosmos-sdk/pull/10021) Speedup coins.AmountOf(), by removing many intermittent regex calls.

### Bug Fixes

* (x/genutil) [#10104](https://github.com/cosmos/cosmos-sdk/pull/10104) Ensure the `init` command reads the `--home` flag value correctly.
Expand Down
1 change: 1 addition & 0 deletions types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ func (coins Coins) Find(denom string) (bool, Coin) {
return false, Coin{}

default:
// Binary search the amount of coins remaining
midIdx := len(coins) / 2 // 2:1, 3:1, 4:2
coin := coins[midIdx]
switch {
Expand Down

0 comments on commit 4df15b5

Please sign in to comment.