Changeset 13720


Ignore:
Timestamp:
Dec 30, 2012, 1:28:28 AM (8 years ago)
Author:
jordan
Message:

(qt) small speedup when rebuilding the activity combobox's counts: walk the torrent model just once, rather than once per activity

Location:
trunk/qt
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/filterbar.cc

    r13719 r13720  
    547547  QAbstractItemModel * model = myActivityCombo->model();
    548548
     549  int torrentsPerMode[FilterMode::NUM_MODES] = { };
     550  myFilter.countTorrentsPerMode (torrentsPerMode);
     551
    549552  for (int row=0, n=model->rowCount(); row<n; ++row)
    550553    {
    551554      QModelIndex index = model->index (row, 0);
    552555      const int mode = index.data(ActivityRole).toInt();
    553       model->setData (index, getCountString(myFilter.count(mode)), TorrentCountRole);
     556      model->setData (index, getCountString(torrentsPerMode[mode]), TorrentCountRole);
    554557    }
    555558
  • trunk/qt/torrent-filter.cc

    r12653 r13720  
    1111 */
    1212
     13#include <algorithm>
    1314#include <iostream>
    1415
     
    206207}
    207208
    208 int
    209 TorrentFilter :: count( const FilterMode& mode ) const
    210 {
    211     int count = 0;
    212 
    213     for( int row=0; ; ++row ) {
    214         QModelIndex index = sourceModel()->index( row, 0 );
    215         if( !index.isValid( ) )
    216             break;
    217         const Torrent * tor = index.data( TorrentModel::TorrentRole ).value<const Torrent*>();
    218         if( activityFilterAcceptsTorrent( tor, mode ) )
    219             ++count;
    220     }
    221 
    222     return count;
    223 }
     209void
     210TorrentFilter :: countTorrentsPerMode (int * setmeCounts) const
     211{
     212  std::fill_n (setmeCounts, FilterMode::NUM_MODES, 0);
     213
     214  for (int row(0); ; ++row)
     215    {
     216      QModelIndex index (sourceModel()->index(row, 0));
     217      if (!index.isValid())
     218        break;
     219
     220      const Torrent * tor (index.data( TorrentModel::TorrentRole ).value<const Torrent*>());
     221      for (int mode(0); mode<FilterMode::NUM_MODES; ++mode)
     222        if (activityFilterAcceptsTorrent (tor, mode))
     223          ++setmeCounts[mode];
     224    }
     225}
     226
  • trunk/qt/torrent-filter.h

    r11092 r13720  
    4949
    5050    public:
    51         int count( const FilterMode& ) const;
     51        void countTorrentsPerMode (int * setmeCounts) const;
    5252
    5353    private:
Note: See TracChangeset for help on using the changeset viewer.