From: Jordan Lee Date: Tue, 10 May 2011 04:46:44 +0000 (+0000) Subject: (trunk libT) CPU improvement in torrent.c's torrentInit() X-Git-Tag: 2.30~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=94cc3f87f7d7e96d4ef96ffe850b5355a2994441;p=transmission (trunk libT) CPU improvement in torrent.c's torrentInit() 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. --- diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 960f6003f..2d454e810 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -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 ); + } } } diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index b4e942ffe..825c6e92f 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -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 );