1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-23 08:13:27 +00:00

(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().

This commit is contained in:
Charles Kerr 2009-05-21 19:54:59 +00:00
parent b1f675eb83
commit 59e4a61100
2 changed files with 35 additions and 20 deletions

View file

@ -74,6 +74,7 @@ getOldTorrentFilename( const tr_session * session,
return ret;
}
/* this is for really old versions of T and will probably be removed someday */
void
tr_metainfoMigrate( tr_session * session,
tr_info * inf )

View file

@ -529,7 +529,6 @@ tr_sessionSaveSettings( tr_session * session,
tr_bencFree( &settings );
}
static void metainfoLookupRescan( tr_session * );
static void tr_sessionInitImpl( void * );
static void onAltTimer( int, short, void* );
static void setAltTimer( tr_session * session );
@ -834,7 +833,6 @@ tr_sessionInitImpl( void * vdata )
tr_statsInit( session );
session->web = tr_webInit( session );
metainfoLookupRescan( session );
session->isWaiting = FALSE;
dbgmsg( "returning session %p; session->tracker is %p", session, session->tracker );
@ -1781,19 +1779,6 @@ compareHashStringToLookupEntry( const void * va, const void * vb )
return strcmp( a, b->hashString );
}
const char*
tr_sessionFindTorrentFile( const tr_session * session,
const char * hashStr )
{
struct tr_metainfo_lookup * l = bsearch( hashStr,
session->metainfoLookup,
session->metainfoLookupCount,
sizeof( struct tr_metainfo_lookup ),
compareHashStringToLookupEntry );
return l ? l->filename : NULL;
}
static void
metainfoLookupRescan( tr_session * session )
{
@ -1852,17 +1837,46 @@ metainfoLookupRescan( tr_session * session )
tr_dbg( "Found %d torrents in \"%s\"", n, dirname );
}
static struct tr_metainfo_lookup *
metainfoLookup( const tr_session * session, const char * hashString )
{
/* because only the mac client uses metainfoLookup, and because building
* the lookup is expensive, we hold off on building it until the client
* actually asks to look up a hash... */
if( !session->metainfoLookupCount )
metainfoLookupRescan( (tr_session*)session );
return bsearch( hashString,
session->metainfoLookup,
session->metainfoLookupCount,
sizeof( struct tr_metainfo_lookup ),
compareHashStringToLookupEntry );
}
const char*
tr_sessionFindTorrentFile( const tr_session * session,
const char * hashString )
{
const struct tr_metainfo_lookup * l = metainfoLookup( session, hashString );
return l ? l->filename : NULL;
}
void
tr_sessionSetTorrentFile( tr_session * session,
const char * hashString,
const char * filename )
{
struct tr_metainfo_lookup * l = bsearch( hashString,
session->metainfoLookup,
session->metainfoLookupCount,
sizeof( struct tr_metainfo_lookup ),
compareHashStringToLookupEntry );
struct tr_metainfo_lookup * l;
/* since we walk session->configDir/torrents/ to build the lookup table,
* and tr_sessionSetTorrentFile() is just to tell us there's a new file
* in that same directory, we don't need to do anything here if the
* lookup table hasn't been built yet */
if( session->metainfoLookup == NULL )
return;
l = metainfoLookup( session, hashString );
if( l )
{
if( l->filename != filename )