Optimize ProjectTree for adding folders/files

Instead of searching the whole tree for the current node,
only check the newly added files/folders.

Change-Id: I015a955815223767367c4cad476d0620f69abd71
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Daniel Teske
2015-03-03 15:11:01 +01:00
parent 159f4e4f39
commit facc89fafd
4 changed files with 52 additions and 7 deletions

View File

@@ -237,11 +237,16 @@ void ProjectTreeWidget::rowsInserted(const QModelIndex &parent, int start, int e
}
Node *ProjectTreeWidget::nodeForFile(const Utils::FileName &fileName)
{
return mostExpandedNode(SessionManager::nodesForFile(fileName));
}
Node *ProjectTreeWidget::mostExpandedNode(const QList<Node *> &nodes)
{
Node *bestNode = 0;
int bestNodeExpandCount = INT_MAX;
foreach (Node *node, SessionManager::nodesForFile(fileName)) {
foreach (Node *node, nodes) {
if (!bestNode) {
bestNode = node;
bestNodeExpandCount = ProjectTreeWidget::expandedCount(node);
@@ -256,7 +261,6 @@ Node *ProjectTreeWidget::nodeForFile(const Utils::FileName &fileName)
}
}
}
return bestNode;
}