]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Simplify request ordering for reversed conditions
authorMatt Joiner <anacrolix@gmail.com>
Tue, 12 Oct 2021 01:31:47 +0000 (12:31 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 19 Oct 2021 03:08:56 +0000 (14:08 +1100)
requesting.go

index 027365e381534621eac280b1048633fc4ca49184..eb69549b210e105675b60a9e060446f6f85ba575 100644 (file)
@@ -159,10 +159,11 @@ func (p peerRequests) Less(i, j int) bool {
        ml = ml.Int(
                pending(leftRequest, leftCurrent),
                pending(rightRequest, rightCurrent))
-       ml = ml.Bool(rightCurrent, leftCurrent)
+       ml = ml.Bool(!leftCurrent, !rightCurrent)
        ml = ml.Int(
-               int(p.torrentStrategyInput.Pieces[rightPieceIndex].Priority),
-               int(p.torrentStrategyInput.Pieces[leftPieceIndex].Priority))
+               -int(p.torrentStrategyInput.Pieces[leftPieceIndex].Priority),
+               -int(p.torrentStrategyInput.Pieces[rightPieceIndex].Priority),
+       )
        ml = ml.Int(
                int(p.torrentStrategyInput.Pieces[leftPieceIndex].Availability),
                int(p.torrentStrategyInput.Pieces[rightPieceIndex].Availability))
@@ -171,7 +172,7 @@ func (p peerRequests) Less(i, j int) bool {
        return ml.MustLess()
 }
 
-func (p peerRequests) Swap(i, j int) {
+func (p *peerRequests) Swap(i, j int) {
        p.requestIndexes[i], p.requestIndexes[j] = p.requestIndexes[j], p.requestIndexes[i]
 }