From a893e685b02590ec4edd3062ce5841881c1edbd6 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Wed, 19 Nov 2014 20:01:32 -0600 Subject: [PATCH] Don't allocate pieces map unless necessary when filling responsive requests --- download_strategies.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/download_strategies.go b/download_strategies.go index bc728759..e0e79814 100644 --- a/download_strategies.go +++ b/download_strategies.go @@ -176,6 +176,9 @@ type requestFiller struct { // Wrapper around connection.request that tracks request heat. func (me *requestFiller) request(req request) bool { + if me.pieces == nil { + me.pieces = make(map[int]struct{}) + } me.pieces[int(req.Index)] = struct{}{} if me.c.RequestPending(req) { return true @@ -330,7 +333,7 @@ func (me *requestFiller) readahead() bool { } func (me *responsiveDownloadStrategy) FillRequests(t *torrent, c *connection) (pieces []int) { - rf := requestFiller{c, t, me, make(map[int]struct{}, t.NumPieces())} + rf := requestFiller{c: c, t: t, s: me} rf.Run() for p := range rf.pieces { pieces = append(pieces, p) -- 2.48.1