]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Break up long condition expression
authorMatt Joiner <anacrolix@gmail.com>
Mon, 15 Jan 2024 01:44:33 +0000 (12:44 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 15 Jan 2024 01:55:32 +0000 (12:55 +1100)
requesting.go

index d961fba48946c7364dd7c4c3b06df0d66ceff657..b70f2645e990b234b28703ab64927d42ae31d1a9 100644 (file)
@@ -260,7 +260,14 @@ func (p *Peer) applyRequestState(next desiredRequestState) {
 
        t := p.t
        originalRequestCount := current.Requests.GetCardinality()
-       for requestHeap.Len() != 0 && maxRequests(current.Requests.GetCardinality()+current.Cancelled.GetCardinality()) < p.nominalMaxRequests() {
+       for {
+               if requestHeap.Len() == 0 {
+                       break
+               }
+               numPending := maxRequests(current.Requests.GetCardinality() + current.Cancelled.GetCardinality())
+               if numPending >= p.nominalMaxRequests() {
+                       break
+               }
                req := heap.Pop(requestHeap)
                existing := t.requestingPeer(req)
                if existing != nil && existing != p {