]> granicus.if.org Git - transmission/commitdiff
(trunk libT) minor CPU improvement to peer-mgr.c's bandwidthPulse()
authorJordan Lee <jordan@transmissionbt.com>
Tue, 10 May 2011 14:41:59 +0000 (14:41 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Tue, 10 May 2011 14:41:59 +0000 (14:41 +0000)
We looped through all the torrents 3x to do three separate tasks... instead, loop only once and do the three tasks inside the single loop.

libtransmission/peer-mgr.c

index 963a5a9762ee8e534f7e4705406dfc48b541801c..723c5ae4c6f8d4e725bdf0224db79d5e550712f1 100644 (file)
@@ -3556,26 +3556,24 @@ bandwidthPulse( int foo UNUSED, short bar UNUSED, void * vmgr )
     tr_bandwidthAllocate( &mgr->session->bandwidth, TR_UP, BANDWIDTH_PERIOD_MSEC );
     tr_bandwidthAllocate( &mgr->session->bandwidth, TR_DOWN, BANDWIDTH_PERIOD_MSEC );
 
-    /* possibly stop torrents that have seeded enough */
+    /* torrent upkeep */
     tor = NULL;
     while(( tor = tr_torrentNext( mgr->session, tor )))
+    {
+        /* possibly stop torrents that have seeded enough */
         tr_torrentCheckSeedLimit( tor );
 
-    /* run the completeness check for any torrents that need it */
-    tor = NULL;
-    while(( tor = tr_torrentNext( mgr->session, tor ))) {
+        /* run the completeness check for any torrents that need it */
         if( tor->torrentPeers->needsCompletenessCheck ) {
             tor->torrentPeers->needsCompletenessCheck  = false;
             tr_torrentRecheckCompleteness( tor );
         }
-    }
 
-    /* stop torrents that are ready to stop, but couldn't be stopped earlier
-     * during the peer-io callback call chain */
-    tor = NULL;
-    while(( tor = tr_torrentNext( mgr->session, tor )))
+        /* stop torrents that are ready to stop, but couldn't be stopped
+           earlier during the peer-io callback call chain */
         if( tor->isStopping )
             tr_torrentStop( tor );
+    }
 
     reconnectPulse( 0, 0, mgr );