summaryrefslogtreecommitdiff
path: root/src/plugins/diffeditor/diffeditorplugin.cpp
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2022-09-22 13:48:54 +0200
committerJarek Kobus <jaroslaw.kobus@qt.io>2022-09-28 15:47:39 +0000
commit054d7d65d2ea136a21090bf3e7672c4954aa0fca (patch)
treec9f440b823bb852f7b5571828b3c6a13e33ed87a /src/plugins/diffeditor/diffeditorplugin.cpp
parent5c0cafa68ea16c370da7469882671f7be62a13b9 (diff)
downloadqt-creator-054d7d65d2ea136a21090bf3e7672c4954aa0fca.tar.gz
UnifiedDiffEditor: Move showing diff into separate thread
Before, when all the data was finished, we called showDiff() in main thread. This consisted of 2 parts: 1. Calculating some extra data and generating actual text for UnifiedDiffEditor out of input data. 2. Calling setPlainText() with generated text. For a really big diffs this could freeze the main thread for a couple of seconds. Like e.g. 05c35356abc31549c5db6eba31fb608c0365c2a0 (initial Creator import) - it contained 7 million characters, part 1. took about 500 ms and part 2. took about 2.5 seconds. This two tasks are now done in separate thread. However, since we can't call TextEditorWidget::setPlainText() directly from non-GUI thread, we create a separate TextDocument object in the worker thread, fill it with generated diff input and move the TextDocument object into the main thread as a result of async computation. In main thread we replace TextDocument object of the TextEditorWidget with the one generated in other thread. This replacement is very fast. Change-Id: I49a717ced1dc2d5b8946e0fd6bee244b25071f35 Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/plugins/diffeditor/diffeditorplugin.cpp')
-rw-r--r--src/plugins/diffeditor/diffeditorplugin.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/plugins/diffeditor/diffeditorplugin.cpp b/src/plugins/diffeditor/diffeditorplugin.cpp
index 2b22500a2b..7d97880357 100644
--- a/src/plugins/diffeditor/diffeditorplugin.cpp
+++ b/src/plugins/diffeditor/diffeditorplugin.cpp
@@ -2,7 +2,6 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#include "diffeditorplugin.h"
-#include "diffeditor.h"
#include "diffeditorconstants.h"
#include "diffeditorcontroller.h"
#include "diffeditordocument.h"
@@ -24,10 +23,10 @@
#include <texteditor/textdocument.h>
#include <texteditor/texteditor.h>
-#include "texteditor/texteditoractionhandler.h"
#include <utils/algorithm.h>
#include <utils/differ.h>
+#include <utils/futuresynchronizer.h>
#include <utils/mapreduce.h>
#include <utils/qtcassert.h>
@@ -440,12 +439,14 @@ public:
QAction *m_diffCurrentFileAction = nullptr;
QAction *m_diffOpenFilesAction = nullptr;
- DiffEditorFactory editorFactory;
- DiffEditorServiceImpl service;
+ DiffEditorFactory m_editorFactory;
+ DiffEditorServiceImpl m_service;
+ FutureSynchronizer m_futureSynchronizer;
};
DiffEditorPluginPrivate::DiffEditorPluginPrivate()
{
+ m_futureSynchronizer.setCancelOnWait(true);
//register actions
ActionContainer *toolsContainer
= ActionManager::actionContainer(Core::Constants::M_TOOLS);
@@ -571,9 +572,17 @@ void DiffEditorPluginPrivate::diffExternalFiles()
document->reload();
}
+static DiffEditorPlugin *s_instance = nullptr;
+
+DiffEditorPlugin::DiffEditorPlugin()
+{
+ s_instance = this;
+}
+
DiffEditorPlugin::~DiffEditorPlugin()
{
delete d;
+ s_instance = nullptr;
}
bool DiffEditorPlugin::initialize(const QStringList &arguments, QString *errorMessage)
@@ -586,6 +595,13 @@ bool DiffEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
return true;
}
+void DiffEditorPlugin::addFuture(const QFuture<void> &future)
+{
+ QTC_ASSERT(s_instance, return);
+ s_instance->d->m_futureSynchronizer.addFuture(future);
+}
+
+
} // namespace Internal
} // namespace DiffEditor