From 147ad311358e7229781746748da5a40fb4d3c392 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 1 Jul 2014 00:03:07 +1000 Subject: [PATCH] A CPU optimization to FillRequests when we know no more can be added --- download_strategies.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/download_strategies.go b/download_strategies.go index 2cc7289e..8be1be40 100644 --- a/download_strategies.go +++ b/download_strategies.go @@ -16,6 +16,14 @@ type DefaultDownloadStrategy struct { } func (s *DefaultDownloadStrategy) FillRequests(t *torrent, c *connection) { + if c.Interested { + if c.PeerChoked { + return + } + if len(c.Requests) >= c.PeerMaxRequests { + return + } + } th := s.heat[t] addRequest := func(req request) (again bool) { piece := t.Pieces[req.Index]