From 6184e7704fee7df8110cd7db9557283074292808 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Tue, 24 Mar 2026 16:37:22 +0000 Subject: [PATCH] avoid alloc --- cmd/utils/cmd.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index 486db16aed..95030a3e9c 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -273,6 +273,8 @@ func ImportHistory(chain *core.BlockChain, dir string, network string, from func start = time.Now() reported = time.Now() imported = 0 + h = sha256.New() + buf = bytes.NewBuffer(nil) ) for i, file := range entries { @@ -286,11 +288,12 @@ func ImportHistory(chain *core.BlockChain, dir string, network string, from func } defer f.Close() - h := sha256.New() if _, err := io.Copy(h, f); err != nil { return fmt.Errorf("checksum %s: %w", path, err) } - got := common.BytesToHash(h.Sum(nil)).Hex() + got := common.BytesToHash(h.Sum(buf.Bytes()[:])).Hex() + h.Reset() + buf.Reset() if got != checksums[i] { return fmt.Errorf("%s checksum mismatch: have %s want %s", file, got, checksums[i]) }