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>
This commit is contained in:
Erik Verbruggen
2013-05-15 12:46:08 +02:00
committed by Nikolai Kosjar
parent f6833168ac
commit 0f2a0d9358
3 changed files with 35 additions and 8 deletions

View File

@@ -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;
}