Changeset 13384


Ignore:
Timestamp:
Jul 13, 2012, 12:27:04 AM (9 years ago)
Author:
jordan
Message:

(trunk qt) #4961 -- fix dtor regression introduced in previous commit + add extra assertions to help find any remaining unfound errors

Location:
trunk/qt
Files:
2 edited

Legend:

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

    r13383 r13384  
    4545FileTreeItem :: getMyChildRows()
    4646{
    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;
     47    const size_t n = childCount( );
     48
     49    // ensure that all the rows are hashed
     50    while( myFirstUnhashedRow < n )
     51    {
     52      myChildRows.insert (myChildren[myFirstUnhashedRow]->name(), myFirstUnhashedRow);
     53      myFirstUnhashedRow++;
     54    }
     55
     56    return myChildRows;
    5657}
    5758
     
    6162    assert( myChildren.isEmpty( ) );
    6263
    63     const int pos = row();
    64     if( pos < 0 )
    65         assert (0 && "failed to remove");
    66     else {
     64    if( myParent != 0 )
     65    {
     66        const int pos = row( );
     67        assert ((pos>=0) && "couldn't find child in parent's lookup");
    6768        myParent->myChildren.removeAt( pos );
    68         myParent->myChildRowsDirty = true;
     69        myParent->myChildRows.remove( name() );
     70        myParent->myFirstUnhashedRow = pos;
    6971    }
    7072}
     
    7375FileTreeItem :: appendChild( FileTreeItem * child )
    7476{
     77    const size_t n = childCount();
    7578    child->myParent = this;
    76     const size_t n = childCount();
    7779    myChildren.append (child);
    78     myChildRows.insert (child->name(), n);
     80    myFirstUnhashedRow = n;
    7981}
    8082
     
    100102
    101103    if( myParent )
    102       {
     104    {
    103105        i = myParent->getMyChildRows().value (name(), -1);
    104       }
     106        assert (this == myParent->myChildren[i]);
     107    }
    105108
    106109    return i;
     
    419422FileTreeModel :: clearSubtree( const QModelIndex& top )
    420423{
    421     while( hasChildren( top ) )
    422         clearSubtree( index( 0, 0, top ) );
     424    size_t i = rowCount( top );
     425
     426    while( i > 0 )
     427        clearSubtree( index( --i, 0, top ) );
    423428
    424429    delete static_cast<FileTreeItem*>(top.internalPointer());
  • trunk/qt/file-tree.h

    r13383 r13384  
    4646            myPriority(0), myIsWanted(0),
    4747            myHaveSize(0), myTotalSize(0),
    48             myChildRowsDirty(false) { }
     48            myFirstUnhashedRow(0) { }
    4949
    5050    public:
     
    8282        uint64_t myHaveSize;
    8383        uint64_t myTotalSize;
    84         bool myChildRowsDirty;
     84        size_t myFirstUnhashedRow;
    8585};
    8686
Note: See TracChangeset for help on using the changeset viewer.