Changeset 13383


Ignore:
Timestamp:
Jul 12, 2012, 11:37:04 PM (9 years ago)
Author:
jordan
Message:

(trunk, qt) #4961 -- make the file list more responsive when a torrent has an extreme number of files.

Before this patch, the test torrent I had with ~10k files took 8 seconds to load. After this patch, it takes less than 1 second.

Location:
trunk/qt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/file-tree.cc

    r12697 r13383  
    4242****/
    4343
     44QHash<QString,int>&
     45FileTreeItem :: getMyChildRows()
     46{
     47  // if necessary, revalidate the name-to-row mapping
     48  if( myChildRowsDirty ) {
     49      myChildRows.clear();
     50      for (size_t i=0, n=childCount(); i<n; ++i)
     51          myChildRows.insert (child(i)->name(), i);
     52      myChildRowsDirty = false;
     53    }
     54
     55  return myChildRows;
     56}
     57
     58
    4459FileTreeItem :: ~FileTreeItem( )
    4560{
    4661    assert( myChildren.isEmpty( ) );
    4762
    48     if( myParent ) {
    49         const int pos = myParent->myChildren.indexOf( this );
    50         if( pos >= 0 )
    51             myParent->myChildren.removeAt( pos );
    52         else
    53             assert( 0 && "failed to remove" );
     63    const int pos = row();
     64    if( pos < 0 )
     65        assert (0 && "failed to remove");
     66    else {
     67        myParent->myChildren.removeAt( pos );
     68        myParent->myChildRowsDirty = true;
    5469    }
    5570}
     
    5974{
    6075    child->myParent = this;
    61     myChildren.append( child );
     76    const size_t n = childCount();
     77    myChildren.append (child);
     78    myChildRows.insert (child->name(), n);
    6279}
    6380
    6481FileTreeItem *
    65 FileTreeItem :: child( const QString& filename )
    66 {
    67     foreach( FileTreeItem * c, myChildren )
    68         if( c->name() == filename )
    69             return c;
    70 
    71     return 0;
     82FileTreeItem :: child (const QString& filename )
     83{
     84  FileTreeItem * item(0);
     85
     86  const int row = getMyChildRows().value (filename, -1);
     87  if (row != -1)
     88    {
     89      item = child (row);
     90      assert (filename == item->name());
     91    }
     92
     93  return item;
    7294}
    7395
     
    7597FileTreeItem :: row( ) const
    7698{
    77     int i(0);
     99    int i(-1);
    78100
    79101    if( myParent )
    80         i = myParent->myChildren.indexOf( const_cast<FileTreeItem*>(this) );
     102      {
     103        i = myParent->getMyChildRows().value (name(), -1);
     104      }
    81105
    82106    return i;
  • trunk/qt/file-tree.h

    r11092 r13383  
    1818#include <QItemDelegate>
    1919#include <QList>
     20#include <QHash>
    2021#include <QSet>
    2122#include <QSize>
     
    4445            myIndex(fileIndex), myParent(0), myName(name),
    4546            myPriority(0), myIsWanted(0),
    46             myHaveSize(0), myTotalSize(0) { }
     47            myHaveSize(0), myTotalSize(0),
     48            myChildRowsDirty(false) { }
    4749
    4850    public:
     
    7375        FileTreeItem * myParent;
    7476        QList<FileTreeItem*> myChildren;
     77        QHash<QString,int> myChildRows;
     78        QHash<QString,int>& getMyChildRows();
    7579        const QString myName;
    7680        int myPriority;
     
    7882        uint64_t myHaveSize;
    7983        uint64_t myTotalSize;
     84        bool myChildRowsDirty;
    8085};
    8186
Note: See TracChangeset for help on using the changeset viewer.