]> Sergey Matveev's repositories - btrtrc.git/commitdiff
metainfo: Remove reflection dependency for `Piece.Hash()` (#661)
authorYenForYang <YenForYang@users.noreply.github.com>
Sat, 18 Sep 2021 01:35:21 +0000 (20:35 -0500)
committerGitHub <noreply@github.com>
Sat, 18 Sep 2021 01:35:21 +0000 (11:35 +1000)
`copy`  will copy exactly `HashSize` bytes here.

metainfo/piece.go

index b204faae24db17454034038655d1c87df32ab66a..d8895384d0a1858d17bd3d08fdf89dd4672b3f99 100644 (file)
@@ -1,9 +1,5 @@
 package metainfo
 
-import (
-       "github.com/anacrolix/missinggo/v2"
-)
-
 type Piece struct {
        Info *Info // Can we embed the fields here instead, or is it something to do with saving memory?
        i    pieceIndex
@@ -23,7 +19,7 @@ func (p Piece) Offset() int64 {
 }
 
 func (p Piece) Hash() (ret Hash) {
-       missinggo.CopyExact(&ret, p.Info.Pieces[p.i*HashSize:(p.i+1)*HashSize])
+       copy(ret[:], p.Info.Pieces[p.i*HashSize:(p.i+1)*HashSize])
        return
 }