From 30cbda2b2d151db2d862d851b86a7fd2e8b6d83e Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Tue, 14 Sep 2021 12:13:56 +0200 Subject: [PATCH] LanguageClient: Improve use of Client::m_documentsToUpdate In particular, calling keys() and then take() for all the keys is wasteful (and obscures what's going on). Change-Id: Ic66803cf3579a39c23c32f1fc65e2c9399dcc583 Reviewed-by: David Schulz --- src/plugins/languageclient/client.cpp | 28 +++++++++++++-------------- src/plugins/languageclient/client.h | 4 +++- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/plugins/languageclient/client.cpp b/src/plugins/languageclient/client.cpp index c032ae5cabc..9f3ebc4984a 100644 --- a/src/plugins/languageclient/client.cpp +++ b/src/plugins/languageclient/client.cpp @@ -808,7 +808,7 @@ TextEditor::HighlightingResult createHighlightingResult(const SymbolInformation void Client::cursorPositionChanged(TextEditor::TextEditorWidget *widget) { TextEditor::TextDocument *document = widget->textDocument(); - if (m_documentsToUpdate.contains(document)) + if (m_documentsToUpdate.find(document) != m_documentsToUpdate.end()) return; // we are currently changing this document so postpone the DocumentHighlightsRequest QTimer *timer = m_documentHighlightsTimer[widget]; if (!timer) { @@ -1218,7 +1218,7 @@ void Client::resetAssistProviders(TextEditor::TextDocument *document) void Client::sendPostponedDocumentUpdates() { m_documentUpdateTimer.stop(); - if (m_documentsToUpdate.isEmpty()) + if (m_documentsToUpdate.empty()) return; TextEditor::TextEditorWidget *currentWidget = TextEditor::TextEditorWidget::currentTextEditorWidget(); @@ -1228,11 +1228,9 @@ void Client::sendPostponedDocumentUpdates() TextEditor::TextDocument *document; DidChangeTextDocumentNotification notification; }; - - QList updates; - - const QList documents = m_documentsToUpdate.keys(); - for (auto document : documents) { + const auto updates = Utils::transform>(m_documentsToUpdate, + [this](const auto &elem) { + TextEditor::TextDocument * const document = elem.first; const FilePath &filePath = document->filePath(); const auto uri = DocumentUri::fromFilePath(filePath); m_highlights[uri].clear(); @@ -1240,13 +1238,13 @@ void Client::sendPostponedDocumentUpdates() docId.setVersion(m_documentVersions[filePath]); DidChangeTextDocumentParams params; params.setTextDocument(docId); - params.setContentChanges(m_documentsToUpdate.take(document)); + params.setContentChanges(elem.second); + return DocumentUpdate{document, DidChangeTextDocumentNotification(params)}; + }); + m_documentsToUpdate.clear(); - updates.append({document, DidChangeTextDocumentNotification(params)}); - } - - for (const DocumentUpdate &update : qAsConst(updates)) { - sendContent(update.notification); + for (const DocumentUpdate &update : updates) { + sendContent(update.notification, SendDocUpdates::Ignore); emit documentUpdated(update.document); if (currentWidget && currentWidget->textDocument() == update.document) @@ -1423,8 +1421,8 @@ void Client::rehighlight() bool Client::documentUpdatePostponed(const Utils::FilePath &fileName) const { - return Utils::contains(m_documentsToUpdate.keys(), [fileName](const TextEditor::TextDocument *doc) { - return doc->filePath() == fileName; + return Utils::contains(m_documentsToUpdate, [fileName](const auto &elem) { + return elem.first->filePath() == fileName; }); } diff --git a/src/plugins/languageclient/client.h b/src/plugins/languageclient/client.h index 03377ebe15b..b73dcd6bacf 100644 --- a/src/plugins/languageclient/client.h +++ b/src/plugins/languageclient/client.h @@ -62,6 +62,8 @@ #include #include +#include + namespace Core { class IDocument; } namespace ProjectExplorer { class Project; } namespace TextEditor @@ -252,7 +254,7 @@ private: QMap m_openedDocument; QSet m_postponedDocuments; QMap m_documentVersions; - QMap> m_documentsToUpdate; QMap m_documentHighlightsTimer;