- completedMiddlePieces := torrentCompletedPieces.Copy()
- completedMiddlePieces.RemoveRange(0, fileFirstPieceIndex+1)
- completedMiddlePieces.RemoveRange(fileEndPieceIndex-1, bitmap.ToEnd)
- left += int64(numPiecesSpanned-2-completedMiddlePieces.Len()) * torrentUsualPieceSize
+ completedMiddlePieces := torrentCompletedPieces.Clone()
+ completedMiddlePieces.RemoveRange(0, bitmap.BitRange(fileFirstPieceIndex+1))
+ completedMiddlePieces.RemoveRange(bitmap.BitRange(fileEndPieceIndex-1), bitmap.ToEnd)
+ left += int64(numPiecesSpanned-2-pieceIndex(completedMiddlePieces.GetCardinality())) * torrentUsualPieceSize