]> granicus.if.org Git - transmission/commitdiff
(libT) micro-optimizations suggested by cachegrind
authorCharles Kerr <charles@transmissionbt.com>
Mon, 3 Nov 2008 17:01:08 +0000 (17:01 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Mon, 3 Nov 2008 17:01:08 +0000 (17:01 +0000)
libtransmission/completion.c
libtransmission/torrent.c

index 1160e5f9c42a987ec8fd550998f5ab4266dff982..bfc4568df098bc1ff8119ba4e014c20b9ebb4990 100644 (file)
@@ -303,13 +303,19 @@ tr_cpGetStatus( const tr_completion * cp )
 uint64_t
 tr_cpHaveValid( const tr_completion * cp )
 {
-    uint64_t           b = 0;
-    tr_piece_index_t   i;
-    const tr_torrent * tor = cp->tor;
-
-    for( i = 0; i < tor->info.pieceCount; ++i )
+    uint64_t                  b = 0;
+    tr_piece_index_t          i;
+    const tr_torrent        * tor            = cp->tor;
+    const uint64_t            pieceSize      = tor->info.pieceSize;
+    const uint64_t            lastPieceSize  = tor->lastPieceSize;
+    const tr_piece_index_t    lastPiece      = tor->info.pieceCount - 1;
+
+    for( i=0; i!=lastPiece; ++i )
         if( tr_cpPieceIsComplete( cp, i ) )
-            b += tr_torPieceCountBytes( tor, i );
+            b += pieceSize;
+
+    if( tr_cpPieceIsComplete( cp, lastPiece ) )
+        b += lastPieceSize;
 
     return b;
 }
index 341c1d583c8ac373a3b1cf51020d7cc4a57b5c6d..d371a6a03d958b315426bbcb0ed1b743c5893094 100644 (file)
@@ -99,8 +99,9 @@ tr_torrentFindFromHash( tr_handle *     handle,
     tr_torrent * tor = NULL;
 
     while( ( tor = tr_torrentNext( handle, tor ) ) )
-        if( !memcmp( tor->info.hash, torrentHash, SHA_DIGEST_LENGTH ) )
-            return tor;
+        if( *tor->info.hash == *torrentHash )
+            if( !memcmp( tor->info.hash, torrentHash, SHA_DIGEST_LENGTH ) )
+                return tor;
 
     return NULL;
 }