From: Matt Joiner Date: Sun, 14 Aug 2016 12:39:23 +0000 (+1000) Subject: Speed up connection.lastHelpful X-Git-Tag: v1.0.0~615 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=e6d7b526383fc7ff8f61ae4917979736a298e2e5;p=btrtrc.git Speed up connection.lastHelpful Moving to reflection and interfaces has made it a bottleneck. --- 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 }