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. 05c35356ab
(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>
This commit is contained in:
Jarek Kobus
2022-09-22 13:48:54 +02:00
parent 5c0cafa68e
commit 054d7d65d2
6 changed files with 206 additions and 39 deletions

View File

@@ -8,6 +8,11 @@
#include <coreplugin/diffservice.h>
#include <extensionsystem/iplugin.h>
QT_BEGIN_NAMESPACE
template <typename T>
class QFuture;
QT_END_NAMESPACE
namespace DiffEditor {
namespace Internal {
@@ -29,10 +34,15 @@ class DiffEditorPlugin final : public ExtensionSystem::IPlugin
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "DiffEditor.json")
public:
~DiffEditorPlugin() final;
DiffEditorPlugin();
~DiffEditorPlugin();
bool initialize(const QStringList &arguments, QString *errorMessage) final;
template <typename T>
static void addFuture(const QFuture<T> &future) { addFuture(QFuture<void>(future)); }
static void addFuture(const QFuture<void> &future);
private:
class DiffEditorPluginPrivate *d = nullptr;