OSDN Git Service

QmlOutline: Don't use LookupContext due to performance issues
authorKai Koehne <kai.koehne@nokia.com>
Fri, 22 Oct 2010 11:38:20 +0000 (13:38 +0200)
committerKai Koehne <kai.koehne@nokia.com>
Fri, 22 Oct 2010 11:51:22 +0000 (13:51 +0200)
Creating a LookupContext can be sloooow for large projects. We create
one instance for every update in the Outline to get the right icons.

Take a shortcut here and just use the element name directly, ignoring
packages names etc.

This is a hot fix for 2.1, a following patch will change the Icon
retrieval API accordingly.

Reviewed-by: Roberto Raggi
Task-number: QTCREATORBUG-2859

src/plugins/qmljseditor/qmloutlinemodel.cpp
src/plugins/qmljseditor/qmloutlinemodel.h

index c98ca0e..a004804 100644 (file)
@@ -367,11 +367,6 @@ void QmlOutlineModel::update(const SemanticInfo &semanticInfo)
     m_treePos.append(0);
     m_currentItem = invisibleRootItem();
 
-    // Set up lookup context once to do the element type lookup
-    //
-    // We're simplifying here by using the root context everywhere; should be
-    // ok since there is AFAIK no way to introduce new type names in a sub-context.
-    m_context = semanticInfo.lookupContext();
     m_typeToIcon.clear();
     m_itemToNode.clear();
     m_itemToIdNode.clear();
@@ -381,8 +376,6 @@ void QmlOutlineModel::update(const SemanticInfo &semanticInfo)
     QmlOutlineModelSync syncModel(this);
     syncModel(m_semanticInfo.document);
 
-    m_context.clear();
-
     emit updated();
 }
 
@@ -815,26 +808,18 @@ AST::SourceLocation QmlOutlineModel::getLocation(AST::ExpressionNode *exprNode)
 }
 
 QIcon QmlOutlineModel::getIcon(AST::UiQualifiedId *qualifiedId) {
-    const Interpreter::Value *value = m_context->evaluate(qualifiedId);
-
-    if (const Interpreter::ObjectValue *objectValue = value->asObjectValue()) {
-        do {
-            QString module;
-            QString typeName;
-            if (const Interpreter::QmlObjectValue *qmlObjectValue =
-                    dynamic_cast<const Interpreter::QmlObjectValue*>(objectValue)) {
-                module = qmlObjectValue->packageName();
-            }
-            typeName = objectValue->className();
-
-            QIcon icon = m_icons->icon(module, typeName);
-            if (! icon.isNull())
-                return icon;
+    QIcon icon;
+    if (qualifiedId) {
+        QString name = asString(qualifiedId);
+        if (name.contains(QLatin1Char('.')))
+            name = name.split(QLatin1Char('.')).last();
 
-            objectValue = objectValue->prototype(m_context->context());
-        } while (objectValue);
+        // TODO: get rid of namespace prefixes.
+        icon = m_icons->icon("Qt", name);
+        if (icon.isNull())
+            icon = m_icons->icon("QtWebkit", name);
     }
-    return QIcon();
+    return icon;
 }
 
 QString QmlOutlineModel::getAnnotation(AST::UiObjectInitializer *objectInitializer) {
index 3717faa..0da121a 100644 (file)
@@ -120,7 +120,6 @@ private:
     QStandardItem *m_currentItem;
     QmlJS::Icons *m_icons;
 
-    QmlJS::LookupContext::Ptr m_context;
     QHash<QString, QIcon> m_typeToIcon;
     QHash<QmlOutlineItem*,QIcon> m_itemToIcon;
     QHash<QmlOutlineItem*,QmlJS::AST::Node*> m_itemToNode;