Changeset 11799


Ignore:
Timestamp:
Jan 31, 2011, 11:01:46 PM (11 years ago)
Author:
jordan
Message:

(trunk gtk) #3970 "tr_core_update() wastes CPU cycles by toggling the sort mode" -- fixed.

Long description in #3970. Split tr_core's torrent GtkTreeModel? into two models: one low-level unsorted one, and one proxy sorted one. That way we don't have to disable sorting before walking through the low-level one to sync the table's attributes with the tr_torrent and tr_stat.

File:
1 edited

Legend:

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

    r11742 r11799  
    9191    guint           inhibit_cookie;
    9292    gint            busy_count;
    93     GtkTreeModel *  model;
     93    GtkTreeModel *  raw_model;
     94    GtkTreeModel *  sorted_model;
    9495    tr_session *    session;
    9596};
     
    221222***/
    222223
     224static GtkTreeModel *
     225tr_core_raw_model( TrCore * core )
     226{
     227    return isDisposed( core ) ? NULL : core->priv->raw_model;
     228}
     229
     230GtkTreeModel *
     231tr_core_model( TrCore * core )
     232{
     233    return isDisposed( core ) ? NULL : core->priv->sorted_model;
     234}
     235
     236tr_session *
     237tr_core_session( TrCore * core )
     238{
     239    return isDisposed( core ) ? NULL : core->priv->session;
     240}
     241
     242/***
     243****
     244***/
     245
    223246static tr_bool
    224247coreIsBusy( TrCore * core )
     
    447470
    448471static void
    449 setSort( TrCore *     core,
    450          const char * mode,
    451          gboolean     isReversed  )
    452 {
    453     const int              col = MC_TORRENT_RAW;
     472setSort( TrCore * core, const char * mode, gboolean isReversed  )
     473{
     474    const int col = MC_TORRENT_RAW;
    454475    GtkTreeIterCompareFunc sort_func;
    455     GtkSortType            type =
    456         isReversed ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING;
    457     GtkTreeSortable *      sortable =
    458         GTK_TREE_SORTABLE( tr_core_model( core ) );
     476    GtkSortType type = isReversed ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING;
     477    GtkTreeSortable * sortable = GTK_TREE_SORTABLE( tr_core_model( core ) );
    459478
    460479    if( !strcmp( mode, "sort-by-activity" ) )
     
    769788    store = gtk_list_store_newv( MC_ROW_COUNT, types );
    770789
    771     p->model    = GTK_TREE_MODEL( store );
     790    p->raw_model = GTK_TREE_MODEL( store );
     791    p->sorted_model = gtk_tree_model_sort_new_with_model( p->raw_model );
    772792
    773793#ifdef HAVE_DBUS_GLIB
     
    845865}
    846866
    847 GtkTreeModel *
    848 tr_core_model( TrCore * core )
    849 {
    850     return isDisposed( core ) ? NULL : core->priv->model;
    851 }
    852 
    853 tr_session *
    854 tr_core_session( TrCore * core )
    855 {
    856     return isDisposed( core ) ? NULL : core->priv->session;
    857 }
    858 
    859867static char*
    860868get_collated_name( const tr_info * inf )
     
    867875
    868876void
    869 tr_core_add_torrent( TrCore     * self,
    870                      TrTorrent  * gtor,
    871                      gboolean     doNotify )
     877tr_core_add_torrent( TrCore * self, TrTorrent * gtor, gboolean doNotify )
    872878{
    873879    const tr_info * inf = tr_torrent_info( gtor );
     
    876882    char *  collated = get_collated_name( inf );
    877883    char *  trackers = torrentTrackerString( tor );
    878     GtkListStore *  store = GTK_LIST_STORE( tr_core_model( self ) );
     884    GtkListStore *  store = GTK_LIST_STORE( tr_core_raw_model( self ) );
    879885    GtkTreeIter  unused;
    880886
     
    12141220
    12151221static gboolean
    1216 findTorrentInModel( TrCore *      core,
    1217                     int           id,
    1218                     GtkTreeIter * setme )
    1219 {
    1220     int            match = 0;
    1221     GtkTreeIter    iter;
    1222     GtkTreeModel * model = tr_core_model( core );
     1222findTorrentInRawModel( TrCore * core, int id, GtkTreeIter * setme )
     1223{
     1224    int match = 0;
     1225    GtkTreeIter iter;
     1226    GtkTreeModel * model = tr_core_raw_model( core );
    12231227
    12241228    if( gtk_tree_model_iter_children( model, &iter, NULL ) ) do
    1225         {
    1226             tr_torrent * tor;
    1227             gtk_tree_model_get( model, &iter, MC_TORRENT_RAW, &tor, -1 );
    1228             match = tr_torrentId( tor ) == id;
    1229         }
    1230         while( !match && gtk_tree_model_iter_next( model, &iter ) );
     1229    {
     1230        tr_torrent * tor;
     1231        gtk_tree_model_get( model, &iter, MC_TORRENT_RAW, &tor, -1 );
     1232        match = tr_torrentId( tor ) == id;
     1233    }
     1234    while( !match && gtk_tree_model_iter_next( model, &iter ) );
    12311235
    12321236    if( match )
     
    12501254    GtkTreeIter iter;
    12511255
    1252     if( findTorrentInModel( core, id, &iter ) )
     1256    if( findTorrentInRawModel( core, id, &iter ) )
    12531257    {
    12541258        TrTorrent * gtor = NULL;
    12551259        tr_torrent * tor = NULL;
    1256         GtkTreeModel * model = tr_core_model( core );
     1260        GtkTreeModel * model = tr_core_raw_model( core );
    12571261
    12581262        gtk_tree_model_get( model, &iter, MC_TORRENT, &gtor,
     
    13611365
    13621366void
    1363 tr_core_update( TrCore * self )
    1364 {
    1365     int               column;
    1366     GtkSortType       order;
    1367     GtkTreeSortable * sortable;
    1368     GtkTreeModel *    model = tr_core_model( self );
    1369 
    1370     /* pause sorting */
    1371     sortable = GTK_TREE_SORTABLE( model );
    1372     gtk_tree_sortable_get_sort_column_id( sortable, &column, &order );
    1373     gtk_tree_sortable_set_sort_column_id(
    1374         sortable, GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, order );
    1375 
     1367tr_core_update( TrCore * core )
     1368{
    13761369    /* refresh the model */
    1377     gtk_tree_model_foreach( model, update_foreach, NULL );
    1378 
    1379     /* resume sorting */
    1380     gtk_tree_sortable_set_sort_column_id( sortable, column, order );
     1370    gtk_tree_model_foreach( tr_core_raw_model( core ), update_foreach, NULL );
    13811371
    13821372    /* maybe inhibit hibernation */
    1383     maybeInhibitHibernation( self );
     1373    maybeInhibitHibernation( core );
    13841374}
    13851375
     
    17481738{
    17491739    GtkTreeIter iter;
    1750     GtkTreeModel * model = tr_core_model( core );
     1740    GtkTreeModel * model = tr_core_raw_model( core );
    17511741
    17521742    if( gtk_tree_model_get_iter_first( model, &iter ) ) do
     
    17681758tr_core_get_torrent_count( TrCore * core )
    17691759{
    1770     return gtk_tree_model_iter_n_children( tr_core_model( core ), NULL );
     1760    return gtk_tree_model_iter_n_children( tr_core_raw_model( core ), NULL );
    17711761}
    17721762
     
    17751765{
    17761766    GtkTreeIter iter;
    1777     GtkTreeModel * model = tr_core_model( core );
    17781767    size_t activeCount = 0;
     1768    GtkTreeModel * model = tr_core_raw_model( core );
    17791769
    17801770    if( gtk_tree_model_get_iter_first( model, &iter ) ) do
Note: See TracChangeset for help on using the changeset viewer.