ClangTools: optimize generating diagnostic text marks

If we already know the document for a TextMark we are saving a
potentially expensive lookup.

Change-Id: Ib42b9ab5f36492a94846ef819c84c69a5aecf2e4
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2023-06-16 13:23:16 +02:00
parent c7b8ed520d
commit 2ad12b5b2c
3 changed files with 13 additions and 5 deletions

View File

@@ -8,16 +8,19 @@
#include "clangtoolsutils.h"
#include "diagnosticconfigswidget.h"
#include <texteditor/textdocument.h>
#include <utils/utilsicons.h>
#include <utils/stringutils.h>
#include <QAction>
using namespace TextEditor;
namespace ClangTools {
namespace Internal {
DiagnosticMark::DiagnosticMark(const Diagnostic &diagnostic)
: TextEditor::TextMark(diagnostic.location.filePath,
DiagnosticMark::DiagnosticMark(const Diagnostic &diagnostic, TextDocument *document)
: TextMark(document,
diagnostic.location.line,
{Tr::tr("Clang Tools"), Utils::Id(Constants::DIAGNOSTIC_MARK_ID)})
, m_diagnostic(diagnostic)
@@ -57,6 +60,10 @@ DiagnosticMark::DiagnosticMark(const Diagnostic &diagnostic)
});
}
DiagnosticMark::DiagnosticMark(const Diagnostic &diagnostic)
: DiagnosticMark(diagnostic, TextDocument::textDocumentForFilePath(diagnostic.location.filePath))
{}
void DiagnosticMark::disable()
{
if (!m_enabled)

View File

@@ -14,6 +14,7 @@ namespace Internal {
class DiagnosticMark : public TextEditor::TextMark
{
public:
DiagnosticMark(const Diagnostic &diagnostic, TextEditor::TextDocument *document);
explicit DiagnosticMark(const Diagnostic &diagnostic);
void disable();

View File

@@ -268,7 +268,7 @@ void DocumentClangToolRunner::onDone(const AnalyzeOutputData &output)
if (isSuppressed(diagnostic))
continue;
auto mark = new DiagnosticMark(diagnostic);
auto mark = new DiagnosticMark(diagnostic, doc);
mark->toolType = toolType;
if (doc && Utils::anyOf(diagnostic.explainingSteps, &ExplainingStep::isFixIt)) {