aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeander Schulten <Leander.Schulten@rwth-aachen.de>2020-11-17 02:27:31 +0100
committerLeander Schulten <Leander.Schulten@rwth-aachen.de>2020-11-17 13:24:27 +0000
commit8795ecbf5eb1b48183125487f000b4522fc6a7a9 (patch)
tree80f1519c9532ef630b37af2160c528175441d1b8 /src
parentbf852d8fede40c23e2b6bb780115342e0f7a9765 (diff)
CppEditor: Improve performance of QuickFix 'Remove using directive in global scope'
Change-Id: Id929255b5bf39a25b66ea18855b0c3c1f01720f0 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/cppeditor/cppquickfixes.cpp47
1 files changed, 26 insertions, 21 deletions
diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp
index bb0b781c3e..a778caf3dc 100644
--- a/src/plugins/cppeditor/cppquickfixes.cpp
+++ b/src/plugins/cppeditor/cppquickfixes.cpp
@@ -7643,9 +7643,10 @@ class RemoveUsingNamespaceOperation : public CppQuickFixOperation
struct Node
{
Document::Ptr document;
- bool processed = false;
bool hasGlobalUsingDirective = false;
+ int unprocessedParents;
std::vector<std::reference_wrapper<Node>> includes;
+ std::vector<std::reference_wrapper<Node>> includedBy;
Node() = default;
Node(const Node &) = delete;
Node(Node &&) = delete;
@@ -7690,6 +7691,7 @@ private:
const auto filePath = FilePath::fromString(include.resolvedFileName());
if (shouldHandle(filePath)) {
Node &includedNode = includeGraph[filePath];
+ includedNode.includedBy.push_back(node);
node.includes.push_back(includedNode);
}
}
@@ -7715,34 +7717,37 @@ private:
}
}
}
+ for (auto &[_, node] : includeGraph) {
+ Q_UNUSED(_)
+ node.unprocessedParents = static_cast<int>(node.includes.size());
+ }
return includeGraph;
}
void removeAllUsingsAtGlobalScope(CppRefactoringChanges &refactoring)
{
auto includeGraph = buildIncludeGraph(refactoring);
- std::list<std::reference_wrapper<Node>> unprocessedNodes;
+ std::vector<std::reference_wrapper<Node>> nodesWithProcessedParents;
for (auto &[_, node] : includeGraph) {
Q_UNUSED(_)
- unprocessedNodes.push_back(node);
- }
- while (!unprocessedNodes.empty()) {
- for (auto i = unprocessedNodes.begin(); i != unprocessedNodes.end();) {
- Node &node = *i;
- if (Utils::allOf(node.includes, &Node::processed)) {
- CppRefactoringFilePtr file = refactoring.file(node.document->fileName());
- const bool parentHasUsing = Utils::anyOf(node.includes,
- &Node::hasGlobalUsingDirective);
- const int startPos = parentHasUsing
- ? 0
- : RemoveNamespaceVisitor::SearchGlobalUsingDirectivePos;
- const bool noGlobalUsing = refactorFile(file, refactoring.snapshot(), startPos);
- node.hasGlobalUsingDirective = !noGlobalUsing || parentHasUsing;
- node.processed = true;
- i = unprocessedNodes.erase(i);
- } else {
- ++i;
- }
+ if (!node.unprocessedParents)
+ nodesWithProcessedParents.push_back(node);
+ }
+ while (!nodesWithProcessedParents.empty()) {
+ Node &node = nodesWithProcessedParents.back();
+ nodesWithProcessedParents.pop_back();
+ CppRefactoringFilePtr file = refactoring.file(node.document->fileName());
+ const bool parentHasUsing = Utils::anyOf(node.includes, &Node::hasGlobalUsingDirective);
+ const int startPos = parentHasUsing
+ ? 0
+ : RemoveNamespaceVisitor::SearchGlobalUsingDirectivePos;
+ const bool noGlobalUsing = refactorFile(file, refactoring.snapshot(), startPos);
+ node.hasGlobalUsingDirective = !noGlobalUsing || parentHasUsing;
+
+ for (Node &subNode : node.includedBy) {
+ --subNode.unprocessedParents;
+ if (subNode.unprocessedParents == 0)
+ nodesWithProcessedParents.push_back(subNode);
}
}
}