diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2013-12-11 15:19:54 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@digia.com> | 2014-02-05 15:42:46 +0100 |
commit | 58af02f0746befaf84f77e70aff7f9521f68b15f (patch) | |
tree | 502287f7ed91d92e78f6cb23f8c49aafc09b7ec6 /src | |
parent | 408901273500a64438bd168864300f7877877a6b (diff) | |
download | qt-creator-58af02f0746befaf84f77e70aff7f9521f68b15f.tar.gz |
C++: release more futures.
The CPPEditorWidget retained two futures, as did the attached future
watchers retained them too. Together, each future and the watcher held
on to a complete snapshot that would only get released when another
future was set. This could result into retaining old snapshots in
editors that were invisible/unused for long.
Change-Id: I1133e857c620437b4a69b9dad468f6bd458304b8
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/cppeditor/cppeditor.cpp | 118 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppeditor.h | 16 | ||||
-rw-r--r-- | src/plugins/cpptools/cpptoolseditorsupport.cpp | 6 | ||||
-rw-r--r-- | src/plugins/cpptools/cpptoolseditorsupport.h | 2 |
4 files changed, 72 insertions, 70 deletions
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index e71f4cb845..47a1b58854 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -549,19 +549,14 @@ void CPPEditorWidget::ctor() this, SLOT(onDocumentUpdated())); connect(editorSupport, SIGNAL(semanticInfoUpdated(CppTools::SemanticInfo)), this, SLOT(updateSemanticInfo(CppTools::SemanticInfo))); - connect(editorSupport, SIGNAL(highlighterStarted(QFuture<TextEditor::HighlightingResult>*,uint)), - this, SLOT(highlighterStarted(QFuture<TextEditor::HighlightingResult>*,uint))); + connect(editorSupport, SIGNAL(highlighterStarted(QFuture<TextEditor::HighlightingResult>,uint)), + this, SLOT(highlighterStarted(QFuture<TextEditor::HighlightingResult>,uint))); } m_highlightRevision = 0; - connect(&m_highlightWatcher, SIGNAL(resultsReadyAt(int,int)), - SLOT(highlightSymbolUsages(int,int))); - connect(&m_highlightWatcher, SIGNAL(finished()), - SLOT(finishHighlightSymbolUsages())); m_referencesRevision = 0; m_referencesCursorPosition = 0; - connect(&m_referencesWatcher, SIGNAL(finished()), SLOT(markSymbolsNow())); connect(this, SIGNAL(refactorMarkerClicked(TextEditor::RefactorMarker)), this, SLOT(onRefactorMarkerClicked(TextEditor::RefactorMarker))); @@ -854,40 +849,39 @@ void CPPEditorWidget::renameUsages() void CPPEditorWidget::markSymbolsNow() { - if (m_references.isCanceled()) - return; - else if (m_referencesCursorPosition != position()) - return; - else if (m_referencesRevision != editorRevision()) - return; - - const SemanticInfo info = m_lastSemanticInfo; - TranslationUnit *unit = info.doc->translationUnit(); - const QList<int> result = m_references.result(); + QTC_ASSERT(m_referencesWatcher, return); + if (!m_referencesWatcher->isCanceled() + && m_referencesCursorPosition == position() + && m_referencesRevision == editorRevision()) { + const SemanticInfo info = m_lastSemanticInfo; + TranslationUnit *unit = info.doc->translationUnit(); + const QList<int> result = m_referencesWatcher->result(); - QList<QTextEdit::ExtraSelection> selections; + QList<QTextEdit::ExtraSelection> selections; - foreach (int index, result) { - unsigned line, column; - unit->getTokenPosition(index, &line, &column); + foreach (int index, result) { + unsigned line, column; + unit->getTokenPosition(index, &line, &column); - if (column) - --column; // adjust the column position. + if (column) + --column; // adjust the column position. - const int len = unit->tokenAt(index).f.length; + const int len = unit->tokenAt(index).f.length; - QTextCursor cursor(document()->findBlockByNumber(line - 1)); - cursor.setPosition(cursor.position() + column); - cursor.setPosition(cursor.position() + len, QTextCursor::KeepAnchor); + QTextCursor cursor(document()->findBlockByNumber(line - 1)); + cursor.setPosition(cursor.position() + column); + cursor.setPosition(cursor.position() + len, QTextCursor::KeepAnchor); - QTextEdit::ExtraSelection sel; - sel.format = baseTextDocument()->fontSettings().toTextCharFormat(TextEditor::C_OCCURRENCES); - sel.cursor = cursor; - selections.append(sel); + QTextEdit::ExtraSelection sel; + sel.format = baseTextDocument()->fontSettings() + .toTextCharFormat(TextEditor::C_OCCURRENCES); + sel.cursor = cursor; + selections.append(sel); + } + setExtraSelections(CodeSemanticsSelection, selections); } - - setExtraSelections(CodeSemanticsSelection, selections); + m_referencesWatcher.reset(); } static QList<int> lazyFindReferences(Scope *scope, QString code, Document::Ptr doc, @@ -951,12 +945,15 @@ void CPPEditorWidget::markSymbols(const QTextCursor &tc, const SemanticInfo &inf CanonicalSymbol cs(this, info); QString expression; if (Scope *scope = cs.getScopeAndExpression(this, info, tc, &expression)) { - m_references.cancel(); + if (m_referencesWatcher) + m_referencesWatcher->cancel(); + m_referencesWatcher.reset(new QFutureWatcher<QList<int> >); + connect(m_referencesWatcher.data(), SIGNAL(finished()), SLOT(markSymbolsNow())); + m_referencesRevision = info.revision; m_referencesCursorPosition = position(); - m_references = QtConcurrent::run(&lazyFindReferences, scope, expression, info.doc, - info.snapshot); - m_referencesWatcher.setFuture(m_references); + m_referencesWatcher->setFuture(QtConcurrent::run(&lazyFindReferences, scope, expression, + info.doc, info.snapshot)); } else { const QList<QTextEdit::ExtraSelection> selections = extraSelections(CodeSemanticsSelection); @@ -1164,8 +1161,10 @@ void CPPEditorWidget::updateOutlineToolTip() void CPPEditorWidget::updateUses() { - if (editorRevision() != m_highlightRevision) - m_highlighter.cancel(); + if (m_highlightWatcher) { + m_highlightWatcher->cancel(); + m_highlightWatcher.reset(); + } // Block premature semantic info calculation when editor is created. if (m_modelManager && m_modelManager->cppEditorSupport(editor())->initialized()) @@ -1185,32 +1184,29 @@ void CPPEditorWidget::highlightSymbolUsages(int from, int to) if (editorRevision() != m_highlightRevision) return; // outdated - else if (m_highlighter.isCanceled()) + else if (!m_highlightWatcher || m_highlightWatcher->isCanceled()) return; // aborted TextEditor::SyntaxHighlighter *highlighter = baseTextDocument()->syntaxHighlighter(); QTC_ASSERT(highlighter, return); TextEditor::SemanticHighlighter::incrementalApplyExtraAdditionalFormats( - highlighter, m_highlighter, from, to, m_semanticHighlightFormatMap); + highlighter, m_highlightWatcher->future(), from, to, m_semanticHighlightFormatMap); } void CPPEditorWidget::finishHighlightSymbolUsages() { - if (editorRevision() != m_highlightRevision) - return; // outdated - - if (m_highlighter.isCanceled()) - return; // aborted - - else if (m_lastSemanticInfo.doc.isNull()) - return; - - TextEditor::SyntaxHighlighter *highlighter = baseTextDocument()->syntaxHighlighter(); - QTC_ASSERT(highlighter, return); - - TextEditor::SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd( - highlighter, m_highlighter); + QTC_ASSERT(m_highlightWatcher, return); + if (!m_highlightWatcher->isCanceled() + && editorRevision() == m_highlightRevision + && !m_lastSemanticInfo.doc.isNull()) { + TextEditor::SyntaxHighlighter *highlighter = baseTextDocument()->syntaxHighlighter(); + QTC_CHECK(highlighter); + if (highlighter) + TextEditor::SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd(highlighter, + m_highlightWatcher->future()); + } + m_highlightWatcher.reset(); } void CPPEditorWidget::switchDeclarationDefinition(bool inNextSplit) @@ -1612,12 +1608,18 @@ void CPPEditorWidget::semanticRehighlight(bool force) m_modelManager->cppEditorSupport(editor())->recalculateSemanticInfoDetached(force); } -void CPPEditorWidget::highlighterStarted(QFuture<TextEditor::HighlightingResult> *highlighter, +void CPPEditorWidget::highlighterStarted(QFuture<TextEditor::HighlightingResult> highlighter, unsigned revision) { - m_highlighter = *highlighter; m_highlightRevision = revision; - m_highlightWatcher.setFuture(m_highlighter); + + m_highlightWatcher.reset(new QFutureWatcher<TextEditor::HighlightingResult>); + connect(m_highlightWatcher.data(), SIGNAL(resultsReadyAt(int,int)), + SLOT(highlightSymbolUsages(int,int))); + connect(m_highlightWatcher.data(), SIGNAL(finished()), + SLOT(finishHighlightSymbolUsages())); + + m_highlightWatcher->setFuture(highlighter); } void CPPEditorWidget::updateSemanticInfo(const SemanticInfo &semanticInfo) diff --git a/src/plugins/cppeditor/cppeditor.h b/src/plugins/cppeditor/cppeditor.h index b6103acd26..4b9b01f8ff 100644 --- a/src/plugins/cppeditor/cppeditor.h +++ b/src/plugins/cppeditor/cppeditor.h @@ -144,10 +144,10 @@ public: FollowSymbolUnderCursor *followSymbolUnderCursorDelegate(); // exposed for tests -Q_SIGNALS: +signals: void outlineModelIndexChanged(const QModelIndex &index); -public Q_SLOTS: +public slots: void setSortedOutline(bool sort); void switchDeclarationDefinition(bool inNextSplit); void renameSymbolUnderCursor(); @@ -156,7 +156,7 @@ public Q_SLOTS: void showPreProcessorWidget(); void renameUsagesNow(const QString &replacement = QString()); void semanticRehighlight(bool force = false); - void highlighterStarted(QFuture<TextEditor::HighlightingResult> *highlighter, + void highlighterStarted(QFuture<TextEditor::HighlightingResult> highlighter, unsigned revision); protected: @@ -169,10 +169,10 @@ protected: const CPlusPlus::Macro *findCanonicalMacro(const QTextCursor &cursor, CPlusPlus::Document::Ptr doc) const; -protected Q_SLOTS: +protected slots: void slotCodeStyleSettingsChanged(const QVariant &); -private Q_SLOTS: +private slots: void jumpToOutlineElement(int index); void updateOutlineNow(); void updateOutlineIndex(); @@ -254,12 +254,10 @@ private: QList<TextEditor::QuickFixOperation::Ptr> m_quickFixes; bool m_objcEnabled; - QFuture<TextEditor::HighlightingResult> m_highlighter; - QFutureWatcher<TextEditor::HighlightingResult> m_highlightWatcher; + QScopedPointer<QFutureWatcher<TextEditor::HighlightingResult> > m_highlightWatcher; unsigned m_highlightRevision; // the editor revision that requested the highlight - QFuture<QList<int> > m_references; - QFutureWatcher<QList<int> > m_referencesWatcher; + QScopedPointer<QFutureWatcher<QList<int> > > m_referencesWatcher; unsigned m_referencesRevision; int m_referencesCursorPosition; diff --git a/src/plugins/cpptools/cpptoolseditorsupport.cpp b/src/plugins/cpptools/cpptoolseditorsupport.cpp index 2638a127ce..6a31f98f85 100644 --- a/src/plugins/cpptools/cpptoolseditorsupport.cpp +++ b/src/plugins/cpptools/cpptoolseditorsupport.cpp @@ -390,7 +390,7 @@ void CppEditorSupport::startHighlighting() m_highlighter = m_highlightingSupport->highlightingFuture(doc, snapshot); m_lastHighlightRevision = revision; - emit highlighterStarted(&m_highlighter, m_lastHighlightRevision); + emit highlighterStarted(m_highlighter, m_lastHighlightRevision); } else { const unsigned revision = currentSource(false).revision; if (m_lastHighlightRevision == revision) @@ -400,7 +400,7 @@ void CppEditorSupport::startHighlighting() static const Document::Ptr dummyDoc; static const Snapshot dummySnapshot; m_highlighter = m_highlightingSupport->highlightingFuture(dummyDoc, dummySnapshot); - emit highlighterStarted(&m_highlighter, m_lastHighlightRevision); + emit highlighterStarted(m_highlighter, m_lastHighlightRevision); } } @@ -500,6 +500,8 @@ void CppEditorSupport::onCurrentEditorChanged() void CppEditorSupport::releaseResources() { + m_highlighter.cancel(); + m_highlighter = QFuture<TextEditor::HighlightingResult>(); snapshotUpdater()->releaseSnapshot(); QMutexLocker semanticLocker(&m_lastSemanticInfoLock); m_lastSemanticInfo = SemanticInfo(); diff --git a/src/plugins/cpptools/cpptoolseditorsupport.h b/src/plugins/cpptools/cpptoolseditorsupport.h index f9ba876256..1d6179e5d8 100644 --- a/src/plugins/cpptools/cpptoolseditorsupport.h +++ b/src/plugins/cpptools/cpptoolseditorsupport.h @@ -132,7 +132,7 @@ signals: void documentUpdated(); void diagnosticsChanged(); void semanticInfoUpdated(CppTools::SemanticInfo); - void highlighterStarted(QFuture<TextEditor::HighlightingResult> *, unsigned revision); + void highlighterStarted(QFuture<TextEditor::HighlightingResult>, unsigned revision); private slots: void onMimeTypeChanged(); |