From a0079b171f98865d34f3e5750b87da8e86968d0a Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 7 Dec 2020 15:19:35 +0100 Subject: Make canceling of Type Hierarchy evaluation more responsive On the beginning of the process of evaluating type hierarchy the evaluating thread may freeze on a first call to Snapshot::updateDependencyTable() for quite a long time (e.g. when showing the type hierarchy for IPlugin class inside Creator project - it may freeze up to about 3 seconds). So, when we want to cancel the evaluation (e.g. when we switch from "Type Hierarchy" into another view or when closing Creator) we may freeze for this period. In order to fix it we pass a future interface as an additional argument for Snapshot::updateDependencyTable() and cancel the update when cancellation of task was requested. Change-Id: I2147f10a68989587476c30369ec2ac552a57d5ae Reviewed-by: hjk Reviewed-by: Christian Kandeler --- src/libs/cplusplus/DependencyTable.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/libs/cplusplus/DependencyTable.cpp') diff --git a/src/libs/cplusplus/DependencyTable.cpp b/src/libs/cplusplus/DependencyTable.cpp index 4a2b71d053..2f6b4600f8 100644 --- a/src/libs/cplusplus/DependencyTable.cpp +++ b/src/libs/cplusplus/DependencyTable.cpp @@ -26,6 +26,7 @@ #include "CppDocument.h" #include +#include using namespace CPlusPlus; @@ -47,13 +48,16 @@ Utils::FilePaths DependencyTable::filesDependingOn(const Utils::FilePath &fileNa return deps; } -void DependencyTable::build(const Snapshot &snapshot) +void DependencyTable::build(QFutureInterfaceBase &futureInterface, const Snapshot &snapshot) { files.clear(); fileIndex.clear(); includes.clear(); includeMap.clear(); + if (futureInterface.isCanceled()) + return; + const int documentCount = snapshot.size(); files.resize(documentCount); includeMap.resize(documentCount); @@ -65,6 +69,9 @@ void DependencyTable::build(const Snapshot &snapshot) fileIndex[it.key()] = i; } + if (futureInterface.isCanceled()) + return; + for (int i = 0; i < files.size(); ++i) { const Utils::FilePath &fileName = files.at(i); if (Document::Ptr doc = snapshot.document(fileName)) { @@ -81,10 +88,14 @@ void DependencyTable::build(const Snapshot &snapshot) directIncludes.append(index); bitmap.setBit(index, true); + if (futureInterface.isCanceled()) + return; } includeMap[i] = bitmap; includes[i] = directIncludes; + if (futureInterface.isCanceled()) + return; } } @@ -99,12 +110,18 @@ void DependencyTable::build(const Snapshot &snapshot) foreach (int includedFileIndex, includes.value(i)) { bitmap |= includeMap.value(includedFileIndex); + if (futureInterface.isCanceled()) + return; } if (bitmap != previousBitmap) { includeMap[i] = bitmap; changed = true; } + if (futureInterface.isCanceled()) + return; } + if (futureInterface.isCanceled()) + return; } while (changed); } -- cgit v1.2.1