]> granicus.if.org Git - transmission/commitdiff
(trunk libT) CPU improvement in torrent.c's torrentInit()
authorJordan Lee <jordan@transmissionbt.com>
Tue, 10 May 2011 04:46:44 +0000 (04:46 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Tue, 10 May 2011 04:46:44 +0000 (04:46 +0000)
Add the new torrent to the session's torrent list by prepending it instead of appending it. That way we don't have to walk the list in order to add it. tr_session.torrentList is an unordered list, so there's no real difference between prepending and appending.

libtransmission/peer-mgr.c
libtransmission/torrent.c

index 960f6003f9ae4aa4548f7838bcf2772f6000de74..2d454e810fe90e89ca3c0073af4ad5d1487eab15 100644 (file)
@@ -2829,6 +2829,12 @@ rechokeDownloads( Torrent * t )
     const int peerCount = tr_ptrArraySize( &t->peers );
     const time_t now = tr_time( );
 
+    /* some cases where this function isn't necessary */
+    if( tr_torrentIsSeed( t->tor ) )
+        return;
+    if ( tr_torrentIsPieceTransferAllowed( t->tor, TR_PEER_TO_CLIENT ) )
+        return;
+
     /* decide HOW MANY peers to be interested in */
     {
         int blocks = 0;
@@ -3153,11 +3159,10 @@ rechokePulse( int foo UNUSED, short bar UNUSED, void * vmgr )
     while(( tor = tr_torrentNext( mgr->session, tor ))) {
         if( tor->isRunning ) {
             Torrent * t = tor->torrentPeers;
-            if( tr_ptrArrayEmpty( &t->peers ) )
-                continue;
-            rechokeUploads( t, now );
-            if( !tr_torrentIsSeed( tor ) && tr_torrentIsPieceTransferAllowed( tor, TR_PEER_TO_CLIENT ) )
+            if( !tr_ptrArrayEmpty( &t->peers ) ) {
+                rechokeUploads( t, now );
                 rechokeDownloads( t );
+            }
         }
     }
 
index b4e942ffec761fdcb59526b0c66deca556313055..825c6e92f01c98257e7d33eb56e11cae1e26ca1c 100644 (file)
@@ -868,18 +868,10 @@ torrentInit( tr_torrent * tor, const tr_ctor * ctor )
         tr_torrentSetIdleLimit( tor, tr_sessionGetIdleLimit( tor->session ) );
     }
 
-    {
-        tr_torrent * it = NULL;
-        tr_torrent * last = NULL;
-        while( ( it = tr_torrentNext( session, it ) ) )
-            last = it;
-
-        if( !last )
-            session->torrentList = tor;
-        else
-            last->next = tor;
-        ++session->torrentCount;
-    }
+    /* add the torrent to tr_session.torrentList */
+    tor->next = session->torrentList;
+    session->torrentList = tor;
+    ++session->torrentCount;
 
     /* if we don't have a local .torrent file already, assume the torrent is new */
     isNewTorrent = stat( tor->info.torrent, &st );