Changeset 8465


Ignore:
Timestamp:
May 21, 2009, 7:54:59 PM (12 years ago)
Author:
charles
Message:

(trunk libT) since the metainfo hash string lookup table is expensive to build, and since only the mac client uses it, let's not build it until some non-libT calls tr_ctorSetMetainfoFromHash().

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/metainfo.c

    r8122 r8465  
    7575}
    7676
     77/* this is for really old versions of T and will probably be removed someday */
    7778void
    7879tr_metainfoMigrate( tr_session * session,
  • trunk/libtransmission/session.c

    r8460 r8465  
    530530}
    531531
    532 static void metainfoLookupRescan( tr_session * );
    533532static void tr_sessionInitImpl( void * );
    534533static void onAltTimer( int, short, void* );
     
    835834    tr_statsInit( session );
    836835    session->web = tr_webInit( session );
    837     metainfoLookupRescan( session );
    838836    session->isWaiting = FALSE;
    839837    dbgmsg( "returning session %p; session->tracker is %p", session, session->tracker );
     
    17801778
    17811779    return strcmp( a, b->hashString );
    1782 }
    1783 
    1784 const char*
    1785 tr_sessionFindTorrentFile( const tr_session * session,
    1786                            const char       * hashStr )
    1787 {
    1788     struct tr_metainfo_lookup * l = bsearch( hashStr,
    1789                                              session->metainfoLookup,
    1790                                              session->metainfoLookupCount,
    1791                                              sizeof( struct tr_metainfo_lookup ),
    1792                                              compareHashStringToLookupEntry );
    1793 
    1794     return l ? l->filename : NULL;
    17951780}
    17961781
     
    18531838}
    18541839
     1840static struct tr_metainfo_lookup *
     1841metainfoLookup( const tr_session * session, const char * hashString )
     1842{
     1843    /* because only the mac client uses metainfoLookup, and because building
     1844     * the lookup is expensive, we hold off on building it until the client
     1845     * actually asks to look up a hash... */
     1846    if( !session->metainfoLookupCount )
     1847        metainfoLookupRescan( (tr_session*)session );
     1848
     1849    return bsearch( hashString,
     1850                    session->metainfoLookup,
     1851                    session->metainfoLookupCount,
     1852                    sizeof( struct tr_metainfo_lookup ),
     1853                    compareHashStringToLookupEntry );
     1854}
     1855
     1856const char*
     1857tr_sessionFindTorrentFile( const tr_session  * session,
     1858                           const char        * hashString )
     1859{
     1860    const struct tr_metainfo_lookup * l = metainfoLookup( session, hashString );
     1861
     1862    return l ? l->filename : NULL;
     1863}
     1864
    18551865void
    18561866tr_sessionSetTorrentFile( tr_session * session,
     
    18581868                          const char * filename )
    18591869{
    1860     struct tr_metainfo_lookup * l = bsearch( hashString,
    1861                                              session->metainfoLookup,
    1862                                              session->metainfoLookupCount,
    1863                                              sizeof( struct tr_metainfo_lookup ),
    1864                                              compareHashStringToLookupEntry );
    1865 
     1870    struct tr_metainfo_lookup * l;
     1871
     1872    /* since we walk session->configDir/torrents/ to build the lookup table,
     1873     * and tr_sessionSetTorrentFile() is just to tell us there's a new file
     1874     * in that same directory, we don't need to do anything here if the
     1875     * lookup table hasn't been built yet */
     1876    if( session->metainfoLookup == NULL )
     1877        return;
     1878
     1879    l = metainfoLookup( session, hashString );
    18661880    if( l )
    18671881    {
Note: See TracChangeset for help on using the changeset viewer.