Performance: Make sure the model list is created once

Creating multiple lists during recursion caused a quite large performance penalty.
This commit is contained in:
Magne Sjaastad
2023-10-13 15:01:39 +02:00
parent bd0ef7f63b
commit 6ce456d43e
2 changed files with 17 additions and 6 deletions

View File

@@ -420,10 +420,9 @@ void PdmUiTreeViewQModel::updateEditorsForSubTree( PdmUiTreeOrdering* root )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::list<QModelIndex> PdmUiTreeViewQModel::allIndicesRecursive( const QModelIndex& current ) const
void PdmUiTreeViewQModel::allIndicesRecursiveImpl( const QModelIndex& current, std::list<QModelIndex>& modelList ) const
{
std::list<QModelIndex> currentAndDescendants;
currentAndDescendants.push_back( current );
modelList.insert( modelList.end(), current );
int rows = rowCount( current );
int cols = columnCount( current );
@@ -431,11 +430,21 @@ std::list<QModelIndex> PdmUiTreeViewQModel::allIndicesRecursive( const QModelInd
{
for ( int col = 0; col < cols; ++col )
{
QModelIndex childIndex = index( row, col, current );
std::list<QModelIndex> subList = allIndicesRecursive( childIndex );
currentAndDescendants.insert( currentAndDescendants.end(), subList.begin(), subList.end() );
QModelIndex childIndex = index( row, col, current );
allIndicesRecursiveImpl( childIndex, modelList );
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::list<QModelIndex> PdmUiTreeViewQModel::allIndicesRecursive( const QModelIndex& current ) const
{
std::list<QModelIndex> currentAndDescendants;
allIndicesRecursiveImpl( current, currentAndDescendants );
return currentAndDescendants;
}

View File

@@ -91,6 +91,8 @@ private:
void emitDataChanged( const QModelIndex& index );
void updateEditorsForSubTree( PdmUiTreeOrdering* root );
void allIndicesRecursiveImpl( const QModelIndex& current, std::list<QModelIndex>& modelList ) const;
PdmUiTreeOrdering* m_treeOrderingRoot;
QStringList m_columnHeaders;
QString m_uiConfigName;