]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Speed up connection.lastHelpful
authorMatt Joiner <anacrolix@gmail.com>
Sun, 14 Aug 2016 12:39:23 +0000 (22:39 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Sun, 14 Aug 2016 12:39:23 +0000 (22:39 +1000)
Moving to reflection and interfaces has made it a bottleneck.

connection.go

index 63bb58fce0c8839faac231d76ca122ae6098bdf0..3e29e3197786cda84c7a8f06190e35de51672cce 100644 (file)
@@ -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
 }