From e6d7b526383fc7ff8f61ae4917979736a298e2e5 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 14 Aug 2016 22:39:23 +1000 Subject: [PATCH] Speed up connection.lastHelpful Moving to reflection and interfaces has made it a bottleneck. --- connection.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/connection.go b/connection.go index 63bb58fc..3e29e319 100644 --- a/connection.go +++ b/connection.go @@ -17,7 +17,6 @@ import ( "github.com/anacrolix/missinggo" "github.com/anacrolix/missinggo/bitmap" "github.com/anacrolix/missinggo/prioritybitmap" - "github.com/anacrolix/missinggo/slices" "github.com/bradfitz/iter" "github.com/anacrolix/torrent/bencode" @@ -684,10 +683,10 @@ func (c *connection) useful() bool { return t.connHasWantedPieces(c) } -func (c *connection) lastHelpful() time.Time { - lasts := []time.Time{c.lastUsefulChunkReceived} - if c.t.seeding() { - lasts = append(lasts, c.lastChunkSent) +func (c *connection) lastHelpful() (ret time.Time) { + ret = c.lastUsefulChunkReceived + if c.t.seeding() && c.lastChunkSent.After(ret) { + ret = c.lastChunkSent } - return missinggo.Max(time.Time.Before, slices.ToEmptyInterface(lasts)...).(time.Time) + return } -- 2.48.1