Changeset 12315 for trunk/gtk/tr-core.c


Ignore:
Timestamp:
Apr 5, 2011, 1:36:37 AM (11 years ago)
Author:
jordan
Message:

(trunk libT) more heap pruning: use a hash, rather than an allocated string in tr-core when watching for a torrent's tracker list to change

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/tr-core.c

    r12234 r12315  
    236236                      G_TYPE_UCHAR,     /* tr_stat.finished */
    237237                      G_TYPE_CHAR,      /* tr_priority_t */
    238                       G_TYPE_STRING,    /* concatenated trackers string */
     238                      G_TYPE_UINT,      /* build_torrent_trackers_hash() */
    239239                      G_TYPE_INT,       /* MC_ERROR */
    240240                      G_TYPE_INT };     /* MC_ACTIVE_PEER_COUNT */
     
    910910}
    911911
    912 static char *
    913 build_torrent_tracker_string( tr_torrent * tor )
     912static unsigned int
     913build_torrent_trackers_hash( tr_torrent * tor )
    914914{
    915915    int i;
    916     GString * str = g_string_new( NULL );
    917     const tr_info * inf = tr_torrentInfo( tor );
     916    const char * pch;
     917    uint64_t hash = 0;
     918    const tr_info * const inf = tr_torrentInfo( tor );
    918919
    919920    for( i=0; i<inf->trackerCount; ++i )
    920         g_string_append( str, inf->trackers[i].announce );
    921 
    922     return g_string_free( str, FALSE );
     921        for( pch=inf->trackers[i].announce; *pch; ++pch )
     922            hash = (hash<<4) ^ (hash>>28) ^ *pch;
     923
     924    return hash;
    923925}
    924926
     
    940942        const char * name = tr_torrentName( tor );
    941943        char * collated = get_collated_name( tor );
    942         char * trackers = build_torrent_tracker_string( tor );
     944        const unsigned int trackers_hash = build_torrent_trackers_hash( tor );
    943945        GtkListStore * store = GTK_LIST_STORE( core_raw_model( core ) );
    944946
     
    955957            MC_FINISHED,          st->finished,
    956958            MC_PRIORITY,          tr_torrentGetPriority( tor ),
    957             MC_TRACKERS,          trackers,
     959            MC_TRACKERS,          trackers_hash,
    958960            -1 );
    959961
     
    965967        /* cleanup */
    966968        g_free( collated );
    967         g_free( trackers );
    968969    }
    969970}
     
    13691370    tr_priority_t oldPriority, newPriority;
    13701371    char * oldCollatedName, * newCollatedName;
    1371     char * oldTrackers, * newTrackers;
     1372    unsigned int oldTrackers, newTrackers;
    13721373    double oldUpSpeed, newUpSpeed;
    13731374    double oldDownSpeed, newDownSpeed;
     
    13991400    newFinished = st->finished;
    14001401    newPriority = tr_torrentGetPriority( tor );
    1401     newTrackers = build_torrent_tracker_string( tor );
     1402    newTrackers = build_torrent_trackers_hash( tor );
    14021403    newUpSpeed = st->pieceUploadSpeed_KBps;
    14031404    newDownSpeed = st->pieceDownloadSpeed_KBps;
     
    14151416        || ( newError != oldError )
    14161417        || ( newActivePeerCount != oldActivePeerCount )
    1417         || tr_strcmp0( oldTrackers, newTrackers )
     1418        || ( newTrackers != oldTrackers )
    14181419        || tr_strcmp0( oldCollatedName, newCollatedName )
    14191420        || gtr_compare_double( newUpSpeed, oldUpSpeed, 3 )
     
    14391440    g_free( newCollatedName );
    14401441    g_free( oldCollatedName );
    1441     g_free( newTrackers );
    1442     g_free( oldTrackers );
    14431442    return FALSE;
    14441443}
Note: See TracChangeset for help on using the changeset viewer.