metainfo: Remove reflection dependency for `Piece.Hash()` (#661)

`copy`  will copy exactly `HashSize` bytes here.
This commit is contained in:
YenForYang 2021-09-17 20:35:21 -05:00 committed by GitHub
parent 35ad29dccc
commit c740cde71b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 5 deletions

View 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
}