This repository was archived by the owner on Jan 20, 2026. It is now read-only.
Commit 20cdc9e
committed
Fix quadratic balance query (#573)
## Describe your changes and provide context
Previously `GetAllBalances` would perform slice copy operation for each
iterator `Next` call due to how `Coin::Add` is implemented. The reason
for the copy is because `Coin:Add` needs to sort the resulting slice.
However this is unnecessary because at the end of `GetAllBalances` the
slice would sorted again anyway. This PR changes the iterator operation
to be a simple append, so that the total time complexity would be O(n)
instead of O(n^2)
## Testing performed to validate your change
unit test1 parent 9fb9a4f commit 20cdc9e
2 files changed
Lines changed: 22 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1939 | 1939 | | |
1940 | 1940 | | |
1941 | 1941 | | |
| 1942 | + | |
| 1943 | + | |
| 1944 | + | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
1942 | 1963 | | |
1943 | 1964 | | |
1944 | 1965 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
0 commit comments