From: Matt Joiner Date: Mon, 15 Jan 2024 01:44:33 +0000 (+1100) Subject: Break up long condition expression X-Git-Tag: v1.53.3~6 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=6e8634e97172224857134b425358521c84517e02;p=btrtrc.git Break up long condition expression --- diff --git a/requesting.go b/requesting.go index d961fba4..b70f2645 100644 --- a/requesting.go +++ b/requesting.go @@ -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 {