mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user