ProjectExplorer: Introduce compareSortedLists

Which compares two sorted lists and returns a diff between them.

Change-Id: I278bd43f1bd999bae6575cbf38cddbdf3ff82418
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
Daniel Teske
2014-02-10 16:05:35 +01:00
parent f7caf3ef4f
commit fba7dcdbaa
3 changed files with 125 additions and 64 deletions

View File

@@ -420,38 +420,12 @@ void CMakeProject::buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::
qSort(oldList.begin(), oldList.end(), sortNodesByPath);
qSort(newList.begin(), newList.end(), sortNodesByPath);
// generate added and deleted list
QList<ProjectExplorer::FileNode *>::const_iterator oldIt = oldList.constBegin();
QList<ProjectExplorer::FileNode *>::const_iterator oldEnd = oldList.constEnd();
QList<ProjectExplorer::FileNode *>::const_iterator newIt = newList.constBegin();
QList<ProjectExplorer::FileNode *>::const_iterator newEnd = newList.constEnd();
QList<ProjectExplorer::FileNode *> added;
QList<ProjectExplorer::FileNode *> deleted;
while (oldIt != oldEnd && newIt != newEnd) {
if ( (*oldIt)->path() == (*newIt)->path()) {
delete *newIt;
++oldIt;
++newIt;
} else if ((*oldIt)->path() < (*newIt)->path()) {
deleted.append(*oldIt);
++oldIt;
} else {
added.append(*newIt);
++newIt;
}
}
ProjectExplorer::compareSortedLists(oldList, newList, deleted, added, sortNodesByPath);
while (oldIt != oldEnd) {
deleted.append(*oldIt);
++oldIt;
}
while (newIt != newEnd) {
added.append(*newIt);
++newIt;
}
qDeleteAll(ProjectExplorer::subtractSortedList(newList, added, sortNodesByPath));
// add added nodes
foreach (ProjectExplorer::FileNode *fn, added) {