From: Matt Joiner Date: Wed, 31 Aug 2016 08:04:11 +0000 (+1000) Subject: Extract chunkSize as a const X-Git-Tag: v1.0.0~600 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=c121615fab5b825ec464dbd59b184f6197b4422c;p=btrtrc.git Extract chunkSize as a const --- diff --git a/storage/boltdb.go b/storage/boltdb.go index a198f488..f65382b3 100644 --- a/storage/boltdb.go +++ b/storage/boltdb.go @@ -10,6 +10,8 @@ import ( "github.com/anacrolix/torrent/metainfo" ) +const chunkSize = 1 << 14 + var ( data = []byte("data") completed = []byte("completed") @@ -85,12 +87,12 @@ func (me *boltDBPiece) ReadAt(b []byte, off int64) (n int, err error) { if db == nil { return nil } - ci := off / (1 << 14) - off %= 1 << 14 + ci := off / chunkSize + off %= chunkSize for len(b) != 0 { ck := me.chunkKey(int(ci)) _b := db.Get(ck[:]) - if len(_b) != 1<<14 { + if len(_b) != chunkSize { break } n1 := copy(b, _b[off:]) @@ -124,10 +126,10 @@ func (me *boltDBPiece) WriteAt(b []byte, off int64) (n int, err error) { if err != nil { return err } - ci := off / (1 << 14) - off %= 1 << 14 + ci := off / chunkSize + off %= chunkSize for len(b) != 0 { - _b := make([]byte, 1<<14) + _b := make([]byte, chunkSize) ck := me.chunkKey(int(ci)) copy(_b, db.Get(ck[:])) n1 := copy(_b[off:], b)