metainfo: Remove reflection dependency for `Piece.Hash()` (#661)
`copy` will copy exactly `HashSize` bytes here.
This commit is contained in:
parent
35ad29dccc
commit
c740cde71b
|
@ -1,9 +1,5 @@
|
||||||
package metainfo
|
package metainfo
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/anacrolix/missinggo/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Piece struct {
|
type Piece struct {
|
||||||
Info *Info // Can we embed the fields here instead, or is it something to do with saving memory?
|
Info *Info // Can we embed the fields here instead, or is it something to do with saving memory?
|
||||||
i pieceIndex
|
i pieceIndex
|
||||||
|
@ -23,7 +19,7 @@ func (p Piece) Offset() int64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Piece) Hash() (ret Hash) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue