From b1a33fae7d0559d07fb9ce61e80112549a9f5839 Mon Sep 17 00:00:00 2001 From: Evgenii Baidakov Date: Mon, 19 Aug 2024 12:13:24 +0400 Subject: [PATCH] compare-deposits: Replace sort.Search with slices.BinarySearchFunc Signed-off-by: Evgenii Baidakov --- scripts/compare-deposits/compare-deposits.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/compare-deposits/compare-deposits.go b/scripts/compare-deposits/compare-deposits.go index db12f60c..005bc140 100644 --- a/scripts/compare-deposits/compare-deposits.go +++ b/scripts/compare-deposits/compare-deposits.go @@ -1,13 +1,13 @@ package main import ( + "cmp" "context" "errors" "fmt" "math/big" "os" "slices" - "sort" "time" "github.com/nspcc-dev/neo-go/pkg/encoding/address" @@ -154,11 +154,17 @@ func cliMain(c *cli.Context) error { maxBlock = h } } - n := sort.Search(int(maxBlock-minBlock), func(i int) bool { + size := int64(maxBlock - minBlock) + blocks := make([]int64, size) + for i := int64(0); i < size; i++ { + blocks[i] = i + } + + n, _ := slices.BinarySearchFunc(blocks, nextSupply, func(i int64, i2 int64) int { var h = minBlock + uint32(i) s := getSupply(cFS, balanceHash, h) knownBlocks[h] = s - return s > nextSupply + return cmp.Compare(s, i2) }) for _, s := range knownBlocks { if s > nextSupply && (s < tmpSupply || tmpSupply == 0) {