From: Matt Joiner <anacrolix@gmail.com>
Date: Tue, 12 Oct 2021 01:31:47 +0000 (+1100)
Subject: Simplify request ordering for reversed conditions
X-Git-Tag: v1.34.0^2~42
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=0a8e66c7fce726de4dbbcaf33446413e965c17a0;p=btrtrc.git

Simplify request ordering for reversed conditions
---

diff --git a/requesting.go b/requesting.go
index 027365e3..eb69549b 100644
--- a/requesting.go
+++ b/requesting.go
@@ -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]
 }