From a444cdc7aa7bcbe13485748536892822adcc3c8c Mon Sep 17 00:00:00 2001
From: con <qtc-committer@nokia.com>
Date: Tue, 11 Jan 2011 17:56:43 +0100
Subject: [PATCH] Limit depth of include scanning to avoid performance
 problems.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Reviewed-by: Thorbjørn Lindeijer
---
 src/plugins/cpptools/cppmodelmanager.cpp | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp
index 1da41b07551..ac57069bdcd 100644
--- a/src/plugins/cpptools/cppmodelmanager.cpp
+++ b/src/plugins/cpptools/cppmodelmanager.cpp
@@ -1211,6 +1211,13 @@ void CppModelManager::updateIncludesInPaths(QFutureInterface<void> &future,
 
     future.setProgressRange(0, paths.size());
 
+    static const int MAX_DEPTH = 3;
+    QList<int> pathDepths;
+    pathDepths.reserve(paths.size());
+    for (int i = 0; i < paths.size(); ++i) {
+        pathDepths.append(0);
+    }
+
     // Add framework header directories to path list
     QStringList frameworkFilter;
     frameworkFilter << QLatin1String("*.framework");
@@ -1223,6 +1230,7 @@ void CppModelManager::updateIncludesInPaths(QFutureInterface<void> &future,
         while (fwIt.hasNext()) {
             QString framework = fwIt.next();
             paths.append(fwPath + QLatin1Char('/') + framework + QLatin1String("/Headers"));
+            pathDepths.append(0);
             framework.chop(10); // remove the ".framework"
             entriesInFrameworkPath.append(framework + QLatin1Char('/'));
         }
@@ -1237,9 +1245,7 @@ void CppModelManager::updateIncludesInPaths(QFutureInterface<void> &future,
             return;
 
         const QString path = paths.takeFirst();
-
-        if (path == QLatin1String("/"))
-            continue;
+        const int depth = pathDepths.takeFirst();
 
         // Skip non-existing paths
         if (!QFile::exists(path))
@@ -1256,7 +1262,7 @@ void CppModelManager::updateIncludesInPaths(QFutureInterface<void> &future,
             const QString fileName = i.next();
             const QFileInfo fileInfo = i.fileInfo();
             QString text = fileInfo.fileName();
-            if (fileInfo.isDir()) {
+            if (depth < MAX_DEPTH && fileInfo.isDir()) {
                 text += QLatin1Char('/');
 
                 // Also scan subdirectory, but avoid endless recursion with symbolic links
@@ -1272,10 +1278,12 @@ void CppModelManager::updateIncludesInPaths(QFutureInterface<void> &future,
                         entriesInPaths.insert(fileName, result.value());
                     } else {
                         paths.append(target);
+                        pathDepths.append(depth + 1);
                         symlinks.append(SymLink(fileName, target));
                     }
                 } else {
                     paths.append(fileName);
+                    pathDepths.append(depth + 1);
                 }
                 entries.append(text);
             } else {
-- 
GitLab