summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2013-05-15 12:46:08 +0200
committerNikolai Kosjar <nikolai.kosjar@digia.com>2013-06-11 13:03:26 +0200
commit0f2a0d93589f0cd7b3603d05cd94743e133972f9 (patch)
tree7511d425b0616b5d34ae78a528e62bdd29b25921
parentf6833168ac9df9c91f1abb25c911bba3aba8446f (diff)
downloadqt-creator-0f2a0d93589f0cd7b3603d05cd94743e133972f9.tar.gz
C++: cache results of linksForIdentifier in HelpItem.
The method linksForIdentifier was called at least thrice when generating a single valid tooltip in the C++ editor. Now the cached, and the cache can be "initialised" during construction. This reduces the time spent for creating a tooltip by 30%. Task-number: QTCREATORBUG-8970 Change-Id: I5130b769e977c6ffced1a87715831386ef0d5319 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
-rw-r--r--src/plugins/cppeditor/cpphoverhandler.cpp14
-rw-r--r--src/plugins/texteditor/helpitem.cpp21
-rw-r--r--src/plugins/texteditor/helpitem.h8
3 files changed, 35 insertions, 8 deletions
diff --git a/src/plugins/cppeditor/cpphoverhandler.cpp b/src/plugins/cppeditor/cpphoverhandler.cpp
index 086595b957..cf7d3bab47 100644
--- a/src/plugins/cppeditor/cpphoverhandler.cpp
+++ b/src/plugins/cppeditor/cpphoverhandler.cpp
@@ -77,11 +77,19 @@ void CppHoverHandler::identifyMatch(TextEditor::ITextEditor *editor, int pos)
const QSharedPointer<CppElement> &cppElement = evaluator.cppElement();
if (!isDiagnosticTooltip())
setToolTip(cppElement->tooltip);
- foreach (const QString &helpId, cppElement->helpIdCandidates) {
- if (!Core::HelpManager::instance()->linksForIdentifier(helpId).isEmpty()) {
+ QStringList candidates = cppElement->helpIdCandidates;
+ candidates.removeDuplicates();
+ HelpManager *hm = HelpManager::instance();
+ foreach (const QString &helpId, candidates) {
+ if (helpId.isEmpty())
+ continue;
+
+ const QMap<QString, QUrl> helpLinks = hm->linksForIdentifier(helpId);
+ if (!helpLinks.isEmpty()) {
setLastHelpItemIdentified(TextEditor::HelpItem(helpId,
cppElement->helpMark,
- cppElement->helpCategory));
+ cppElement->helpCategory,
+ helpLinks));
break;
}
}
diff --git a/src/plugins/texteditor/helpitem.cpp b/src/plugins/texteditor/helpitem.cpp
index f247acdbab..48ce056510 100644
--- a/src/plugins/texteditor/helpitem.cpp
+++ b/src/plugins/texteditor/helpitem.cpp
@@ -32,9 +32,6 @@
#include <coreplugin/helpmanager.h>
#include <utils/htmldocextractor.h>
-#include <QUrl>
-#include <QMap>
-
using namespace TextEditor;
HelpItem::HelpItem()
@@ -48,6 +45,11 @@ HelpItem::HelpItem(const QString &helpId, const QString &docMark, Category categ
m_helpId(helpId), m_docMark(docMark), m_category(category)
{}
+HelpItem::HelpItem(const QString &helpId, const QString &docMark, Category category,
+ const QMap<QString, QUrl> &helpLinks) :
+ m_helpId(helpId), m_docMark(docMark), m_category(category), m_helpLinks(helpLinks)
+{}
+
HelpItem::~HelpItem()
{}
@@ -71,7 +73,9 @@ HelpItem::Category HelpItem::category() const
bool HelpItem::isValid() const
{
- if (!Core::HelpManager::instance()->linksForIdentifier(m_helpId).isEmpty())
+ if (m_helpId.isEmpty())
+ return false;
+ if (!retrieveHelpLinks().isEmpty())
return true;
if (QUrl(m_helpId).isValid())
return true;
@@ -87,7 +91,7 @@ QString HelpItem::extractContent(bool extended) const
htmlExtractor.setMode(Utils::HtmlDocExtractor::FirstParagraph);
QString contents;
- QMap<QString, QUrl> helpLinks = Core::HelpManager::instance()->linksForIdentifier(m_helpId);
+ QMap<QString, QUrl> helpLinks = retrieveHelpLinks();
if (helpLinks.isEmpty()) {
// Maybe this is already an URL...
QUrl url(m_helpId);
@@ -134,3 +138,10 @@ QString HelpItem::extractContent(bool extended) const
}
return contents;
}
+
+QMap<QString, QUrl> HelpItem::retrieveHelpLinks() const
+{
+ if (m_helpLinks.isEmpty())
+ m_helpLinks = Core::HelpManager::instance()->linksForIdentifier(m_helpId);
+ return m_helpLinks;
+}
diff --git a/src/plugins/texteditor/helpitem.h b/src/plugins/texteditor/helpitem.h
index 8a6be8e5b9..ea48f7da3d 100644
--- a/src/plugins/texteditor/helpitem.h
+++ b/src/plugins/texteditor/helpitem.h
@@ -32,7 +32,9 @@
#include "texteditor_global.h"
+#include <QMap>
#include <QString>
+#include <QUrl>
namespace TextEditor {
@@ -55,6 +57,8 @@ public:
HelpItem();
HelpItem(const QString &helpId, Category category);
HelpItem(const QString &helpId, const QString &docMark, Category category);
+ HelpItem(const QString &helpId, const QString &docMark, Category category,
+ const QMap<QString, QUrl> &helpLinks);
~HelpItem();
void setHelpId(const QString &id);
@@ -71,9 +75,13 @@ public:
QString extractContent(bool extended) const;
private:
+ QMap<QString, QUrl> retrieveHelpLinks() const;
+
+private:
QString m_helpId;
QString m_docMark;
Category m_category;
+ mutable QMap<QString, QUrl> m_helpLinks; // cached help links
};
} // namespace TextEditor