avoid alloc

This commit is contained in:
Sina Mahmoodi 2026-03-24 16:37:22 +00:00
parent 858bc9b590
commit 6184e7704f

View file

@ -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])
}