Fix BenchmarkUpdatePiecePriorities

This commit is contained in:
Matt Joiner 2021-12-15 19:09:22 +11:00
parent e7ee568c52
commit ffb98097fa
3 changed files with 16 additions and 0 deletions

View File

@ -5,6 +5,9 @@ import (
)
func (t *Torrent) updatePieceRequestOrder(pieceIndex int) {
if t.storage == nil {
return
}
t.cl.pieceRequestOrder[t.clientPieceRequestOrderKey()].Update(
t.pieceRequestOrderKey(pieceIndex),
t.requestStrategyPieceOrderState(pieceIndex))
@ -18,6 +21,9 @@ func (t *Torrent) clientPieceRequestOrderKey() interface{} {
}
func (t *Torrent) deletePieceRequestOrder() {
if t.storage == nil {
return
}
cpro := t.cl.pieceRequestOrder
key := t.clientPieceRequestOrderKey()
pro := cpro[key]
@ -30,6 +36,9 @@ func (t *Torrent) deletePieceRequestOrder() {
}
func (t *Torrent) initPieceRequestOrder() {
if t.storage == nil {
return
}
if t.cl.pieceRequestOrder == nil {
t.cl.pieceRequestOrder = make(map[interface{}]*request_strategy.PieceRequestOrder)
}
@ -41,6 +50,9 @@ func (t *Torrent) initPieceRequestOrder() {
}
func (t *Torrent) addRequestOrderPiece(i int) {
if t.storage == nil {
return
}
t.cl.pieceRequestOrder[t.clientPieceRequestOrderKey()].Add(
t.pieceRequestOrderKey(i),
t.requestStrategyPieceOrderState(i))

View File

@ -243,6 +243,9 @@ func (t *Torrent) pieceComplete(piece pieceIndex) bool {
}
func (t *Torrent) pieceCompleteUncached(piece pieceIndex) storage.Completion {
if t.storage == nil {
return storage.Completion{Complete: false, Ok: true}
}
return t.pieces[piece].Storage().Completion()
}

View File

@ -89,6 +89,7 @@ func BenchmarkUpdatePiecePriorities(b *testing.B) {
PieceLength: pieceLength,
Length: pieceLength * numPieces,
}))
t.onSetInfo()
assert.EqualValues(b, 13410, t.numPieces())
for i := 0; i < 7; i += 1 {
r := t.NewReader()