]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Several speedups in logic
authorMatt Joiner <anacrolix@gmail.com>
Fri, 17 Jul 2015 11:07:01 +0000 (21:07 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 17 Jul 2015 11:07:01 +0000 (21:07 +1000)
client.go
torrent.go

index 5f7f332f82ab9b099022539a4681796caf6a3a36..281e956691b0f5e689bfb7b5301f33f903dcc081 100644 (file)
--- 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)
                }
index 43d45d5c8c99f16aa53cab968b83dd60605ca484..c263dcafce477e402c9738618bc68defc0c77847 100644 (file)
@@ -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)
 }