From: Matt Joiner Date: Fri, 17 Jul 2015 11:07:01 +0000 (+1000) Subject: Several speedups in logic X-Git-Tag: v1.0.0~1117 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=0600c3b5e398d90e7f8efa8b07c791f25f1a5f9f;p=btrtrc.git Several speedups in logic --- diff --git a/client.go b/client.go index 5f7f332f..281e9566 100644 --- a/client.go +++ b/client.go @@ -1749,8 +1749,11 @@ func (t *torrent) needData() bool { if !t.haveInfo() { return true } - for i := range t.Pieces { - if t.wantPiece(i) { + if len(t.urgent) != 0 { + return true + } + for _, p := range t.Pieces { + if p.Priority != PiecePriorityNone { return true } } @@ -2618,8 +2621,7 @@ func (me *Client) pieceChanged(t *torrent, piece int) { } } conn.pieceRequestOrder.DeletePiece(int(piece)) - } - if t.wantPiece(piece) && conn.PeerHasPiece(piece) { + } else if t.wantPiece(piece) && conn.PeerHasPiece(piece) { t.connPendPiece(conn, int(piece)) me.replenishConnRequests(t, conn) } diff --git a/torrent.go b/torrent.go index 43d45d5c..c263dcaf 100644 --- a/torrent.go +++ b/torrent.go @@ -307,7 +307,7 @@ func (t *torrent) pieceState(index int) (ret PieceState) { if p.QueuedForHash || p.Hashing { ret.Checking = true } - if t.piecePartiallyDownloaded(index) { + if !ret.Complete && t.piecePartiallyDownloaded(index) { ret.Partial = true } return @@ -674,7 +674,13 @@ func (t *torrent) haveChunk(r request) bool { if !t.haveInfo() { return false } + if t.pieceComplete(int(r.Index)) { + return true + } p := t.Pieces[r.Index] + if p.PendingChunkSpecs == nil { + return false + } return !p.pendingChunk(r.chunkSpec, t.chunkSize) }