From c7e47f53bc110f784014a4a1bcb24407612bfce7 Mon Sep 17 00:00:00 2001 From: Kai Koehne <kai.koehne@nokia.com> Date: Fri, 22 Oct 2010 13:38:20 +0200 Subject: [PATCH] QmlOutline: Don't use LookupContext due to performance issues 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 | 35 ++++++--------------- src/plugins/qmljseditor/qmloutlinemodel.h | 1 - 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/src/plugins/qmljseditor/qmloutlinemodel.cpp b/src/plugins/qmljseditor/qmloutlinemodel.cpp index c98ca0e6a53..a004804868c 100644 --- a/src/plugins/qmljseditor/qmloutlinemodel.cpp +++ b/src/plugins/qmljseditor/qmloutlinemodel.cpp @@ -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) { diff --git a/src/plugins/qmljseditor/qmloutlinemodel.h b/src/plugins/qmljseditor/qmloutlinemodel.h index 3717faa450b..0da121abf22 100644 --- a/src/plugins/qmljseditor/qmloutlinemodel.h +++ b/src/plugins/qmljseditor/qmloutlinemodel.h @@ -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; -- GitLab