From f49a85953bc9b78899eff408a5868dfb6055cddc Mon Sep 17 00:00:00 2001
From: Christian Kamm <christian.d.kamm@nokia.com>
Date: Mon, 30 Aug 2010 13:49:23 +0200
Subject: [PATCH] QmlJS: Compute link in SemanticHightlighter thread instead of
 lazily.

It's used very often, so lazy computation (potentially in the gui
thread) was too expensive.

Reviewed-by: Kai Koehne
---
 src/plugins/qmljseditor/qmljseditor.cpp | 11 ++++-------
 src/plugins/qmljseditor/qmljseditor.h   |  7 +++++--
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp
index 4d700da2e73..0336f31ea9b 100644
--- a/src/plugins/qmljseditor/qmljseditor.cpp
+++ b/src/plugins/qmljseditor/qmljseditor.cpp
@@ -556,13 +556,6 @@ QList<AST::Node *> SemanticInfo::astPath(int cursorPosition) const
 
 LookupContext::Ptr SemanticInfo::lookupContext(const QList<QmlJS::AST::Node *> &path) const
 {
-    // create and link context if necessary
-    if (!m_context) {
-        Interpreter::Context *ctx = new Interpreter::Context;
-        Link link(ctx, document, snapshot, ModelManagerInterface::instance()->importPaths());
-        m_context = QSharedPointer<const QmlJS::Interpreter::Context>(ctx);
-    }
-
     return LookupContext::create(document, snapshot, *m_context, path);
 }
 
@@ -1896,6 +1889,10 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
     semanticInfo.snapshot = snapshot;
     semanticInfo.document = doc;
 
+    Interpreter::Context *ctx = new Interpreter::Context;
+    Link link(ctx, doc, snapshot, ModelManagerInterface::instance()->importPaths());
+    semanticInfo.m_context = QSharedPointer<const QmlJS::Interpreter::Context>(ctx);
+
     QStringList importPaths;
     if (m_modelManager)
         importPaths = m_modelManager->importPaths();
diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h
index d905b52ffba..7e83fd8c7c4 100644
--- a/src/plugins/qmljseditor/qmljseditor.h
+++ b/src/plugins/qmljseditor/qmljseditor.h
@@ -114,6 +114,8 @@ public: // attributes
     QTextCursor end;
 };
 
+class SemanticHighlighter;
+
 class SemanticInfo
 {
 public:
@@ -145,8 +147,9 @@ public: // attributes
     QList<QmlJS::DiagnosticMessage> semanticMessages;
 
 private:
-    // created lazily
-    mutable QSharedPointer<const QmlJS::Interpreter::Context> m_context;
+    QSharedPointer<const QmlJS::Interpreter::Context> m_context;
+
+    friend class SemanticHighlighter;
 };
 
 class SemanticHighlighter: public QThread
-- 
GitLab